How to send a mail verification using gmail in Loopback

604 views
Skip to first unread message

Ganesh Pai

unread,
Sep 9, 2017, 2:52:41 PM9/9/17
to LoopbackJS
Hi,

I followed these steps but couldn't succeed. Can anybody pls help. 

Step 1) Created an email connector called Email as follows :

"Email": {
    "name": "Email",
    "defaultForType": "mail",
    "connector": "mail",
    "transports": [
      {
        "type": "SMTP",
        "host": "smtp.gmail.com",
        "secure": true,
        "port": 465,
        "auth": {
          "user": "a...@gmail.com",
          "pass": "abc"
        }
      }
    ]
  }

Step 2) Added entry in model-config.json as follows:
"Email": {
    "dataSource": "Email"
  },

Step 3) In User.js added following function :

module.exports = function(User) {
User.sendEmail = function() {
    User.app.models.Email.send({
      to: 'x...@gmail.com',
      from: 'm...@gmail.com',
      subject: 'my subject',
      text: 'my text',
      html: 'my <em>html</em>'
    }, function(err, mail) {
      console.log('email sent!');
      cb(err);
    });
}

};

When server is up, I am not seeing mail getting sent. Can anybody please help me ?

Thanks.

Dany Van der Meij

unread,
May 24, 2019, 9:15:57 AM5/24/19
to LoopbackJS
Did you find a solution for this?

Maximilian Körner

unread,
May 24, 2019, 9:24:41 AM5/24/19
to loopb...@googlegroups.com
First you might want to log your err object in the cb to get some more info why it fails.

Here is my config, which works for me. Keep in mind, that the error might as well be your mailserver configuration so the loopback is only one part in this scenario.

datasource:

"email": {
"name": "email",
"connector": "mail",
"transports": [
{
"type": "smtp",
"host": "<my_websover_host_address>",
"secure": false,
"port": 587,
"tls": {
"rejectUnauthorized": false
},
"auth": {
"user": "<my_webserver_login_user>",
"pass": "<password>"
}
}
]
}

I'm not using the send function but the builtin email-verification but your function call looks identical to the documentation https://loopback.io/doc/en/lb3/Email-connector.html Notice the additional steps mentioned on this page like connecting the model to the datasource in the model-config.json Hopefully this helps you. cheers

Reply all
Reply to author
Forward
0 new messages