Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mail connector undefined #1971

Closed
DivCorleone opened this issue Nov 1, 2018 · 15 comments
Closed

Mail connector undefined #1971

DivCorleone opened this issue Nov 1, 2018 · 15 comments

Comments

@DivCorleone
Copy link

Steps to reproduce

lb4 datasource 
? Datasource name: mail
? Select the connector for mail: Email (supported by StrongLoop)
? An array of transport configuration objects: [ { "type": "SMTP", "host": "smtp.gmail.com", "secure": true, "port": 465, "tls": { "rejectUnauthorized": false   },  "auth": { "user": "[email protected]",  "pass": "pass"  }  }  ]

index.ts:

export async function main(options: ApplicationConfig = {}) {
  const app = new MaillingApplication(options);
  await app.boot();
  await app.start();

  const url = app.restServer.url;
  console.log(`Server is running at ${url}`);
  console.log(`Try ${url}/ping`);

  let mailer = new MailDataSource;
  console.log('mailer.connector: ', mailer.connector); // undefined

  return app;
}

See Reporting Issues for more tips on writing good issues

@dhmlau dhmlau transferred this issue from strongloop/v4.loopback.io Nov 2, 2018
@dhmlau
Copy link
Member

dhmlau commented Nov 2, 2018

@DivCorleone, I've transferred your issue to loopback-next which is the repo to open LB4 issues.

@dhmlau
Copy link
Member

dhmlau commented Nov 3, 2018

Closing as duplicate of #1971.

@dhmlau dhmlau closed this as completed Nov 3, 2018
@dhmlau dhmlau reopened this Nov 3, 2018
@dhmlau
Copy link
Member

dhmlau commented Nov 3, 2018

Sorry to close your issue by accident. Looks like this issue will be closed if I closed your original ticket.

@dhmlau
Copy link
Member

dhmlau commented Nov 3, 2018

@DivCorleone, may I know what you're trying to accomplish in the code snippet above?
You might want to take a look at this documentation page: https://loopback.io/doc/en/lb3/Email-connector.html. Thanks.

@DivCorleone
Copy link
Author

DivCorleone commented Nov 3, 2018

I'm trying to send mails. I have seen your loopback v3 documentation, but unfortunately i didnt find a way to make it works in lb4 ? I tried reproducing every step in loopback v4 but for me some steps don't stick with lb4. Maybe i am not yet enough experienced with loopback to make it works. So here are the different approaches i tried:

By following the v3 doc:

  • Create a mail datasource using lb4 datasource (step 1 of the doc)

  • Create a model even if config-model.json is not appearing anymore in lb4, by using lb4 model and adding @model({"datasource": "mail"}) to the model decorator to simulate what is made in the doc (step 2). But i think in lb4 that would be more a repository that would be needed than a model defining a shema ? But unfortunaly when running lb4 repository he doesnt find the mail datasource (others work).

  • Try implementing a similar function that the one presented, but unfortunately i had multiple problems: what is the similar app object in lb4 that is use in lb3, there is no more let app = module.exports = loopback() containing all the models ? My newly created mail model has no send method in his definition ? how it is supposed to use it without defining it in a strong typed language and without any heritage ? (step 3)

Having no answer to those questions i tried to do it my way by directly instantiating the MailDataSource, to make it connect, but his connector object is undefined. I tried with lb4 datasource like shown in my first message or like that:

let mailer = new juggler.DataSource('mail', {
    name: "mail",
    connector: "mail",
      "transports": [
    {
      "type": "smtp",
      "host": "smtp.gmail.com",
      "secure": true,
      "port": 465,
      "tls": {
        "rejectUnauthorized": false
      },
      "auth": {
        "user": "[email protected]",
        "pass": "pass"
      }
    }
  ]
   });

console.log('mailer.connector: ', mailer.connector); // undefined

As you can see i'm a bit lost, am i missing something?

I have a wrapper around nodemailer that can do the work, i'm just looking for a more LB4 friendly way of doing it.

@dhmlau
Copy link
Member

dhmlau commented Nov 5, 2018

@DivCorleone, after discussing with @bajtos:

To go forward, what we'll need to do:

  • remove email connector option when running lb4 datasource
  • possibly implement the email connector (extracted from LB3 core) as part of the juggler-next effort

Hope it helps and thanks for reporting this. I'll create the tasks for the 2 to-dos.

@DivCorleone
Copy link
Author

Thank you for the answers, that is good for me so i close the threat.

@ibmjm
Copy link
Contributor

ibmjm commented Apr 9, 2019

@DivCorleone are you able to share a working sample of how you were able to get LB4 to work with nodemailer? I am unable to follow what you did from the brief description your mentioned above, unfortunately.

@DivCorleone
Copy link
Author

Sorry but i never had a working example of nodemailer working inside of LB4. Idk if at this time LB4 mail connector has been implemented. The brief example was just to show that the mail connector was not present in LB4.

@ibmjm
Copy link
Contributor

ibmjm commented Apr 9, 2019

@DivCorleone Oh that's a shame, it sounded like this was closed because you'd reached a viable workaround :(

@DivCorleone
Copy link
Author

Yes, the workaround is to use nodemailer directly. Or use a community connector, but i didnt try this.

@ibmjm
Copy link
Contributor

ibmjm commented Apr 9, 2019

Yes, the workaround is to use nodemailer directly. Or use a community connector, but i didnt try this.

I was able to add a controller to my LB4 application that sends email, by adding let nodemailer = require("nodemailer"); at the top of my controller, and then in my controller class adding a method along these lines:

  async mail() : Promise<any> {
    let transporter = nodemailer.createTransport({
      sendmail: true,
      newline: 'unix',
      path: '/usr/sbin/sendmail'
    });
    return transporter.sendMail({
      from: '[email protected]',
      to: '[email protected]',
      subject: 'Message',
      text: 'I hope this message gets delivered!'
    });
  }

Obviously the method would have to be fleshed out to be useful, and it would be preferable to have a proper LB4 email connector, but I hope this helps someone.

@gautamkriiest
Copy link

Yes, the workaround is to use nodemailer directly. Or use a community connector, but i didnt try this.

I was able to add a controller to my LB4 application that sends email, by adding let nodemailer = require("nodemailer"); at the top of my controller, and then in my controller class adding a method along these lines:

  async mail() : Promise<any> {
    let transporter = nodemailer.createTransport({
      sendmail: true,
      newline: 'unix',
      path: '/usr/sbin/sendmail'
    });
    return transporter.sendMail({
      from: '[email protected]',
      to: '[email protected]',
      subject: 'Message',
      text: 'I hope this message gets delivered!'
    });
  }

Obviously the method would have to be fleshed out to be useful, and it would be preferable to have a proper LB4 email connector, but I hope this helps someone.

do you have working model with LB4 which can trigger email?

@ibmjm
Copy link
Contributor

ibmjm commented Jun 23, 2020

do you have working model with LB4 which can trigger email?

Sorry, I don't understand why you mean by working model... the sample above was in the controller and could use any model needed.

@gautamkriiest
Copy link

do you have working model with LB4 which can trigger email?

Sorry, I don't understand why you mean by working model... the sample above was in the controller and could use any model needed.

please send me service part.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants