Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

node.js email doesn't get sent with gmail smtp

I'm trying to send the email gmail smtp but I'm getting the error:

My email and password is correct I'm using the nodemailer for sending the mail;

       var nodemailer = require('nodemailer');                  // create reusable transporter object using SMTP transport                  var transporter = nodemailer.createTransport({                     service: 'Gmail',                     auth: {                         admin: 'myuseremail.com',                         pass: 'password'                     }                 });                  var mailOptions = {                     from: 'sender address', // sender address                      to: to, // list of receivers                      subject: 'Password Reset', // Subject line                      html: 'Your one time password is : <b>' + temporaryPassword + ' </b>' // html body                  };                  transporter.sendMail(mailOptions, function (error, info) {                     console.log(error,info);               } 

in log i'm getting the error:

    {      [Error: Invalid login]       code: 'EAUTH',       response: '535-5.7.8 Username and Password not accepted. Learn more at\n535 5.7.8  https://support.google.com/mail/answer/14257 k5sm20957041pdo.48 - gsmtp',       responseCode: 535     }  

I try some link but that doesn't work:
https://laracasts.com/discuss/channels/general-discussion/help-email-doesnt-get-sent-with-gmail-smtp

like image 648
Vishnu Mishra Avatar asked Jul 20 '15 12:07

Vishnu Mishra


People also ask

Why is my SMTP for Gmail not working?

In Google Mail, you must allow "less secure" apps access in order for your SMTP settings to work. There are two places this setting must be enabled: The first is here: https://myaccount.google.com/ under “Connected apps & sites.”

Does Gmail SMTP still work?

Does the Gmail SMTP Server Still Work With Two-Factor Authentication? Yes! You can use the SMTP server even if you've enabled two-factor authentication on your Google account. However, you will need to generate an app password so that the app can still connect.


1 Answers

var transporter = nodemailer.createTransport({   service: 'Gmail',   auth: {     user: '[email protected]',     pass: 'password'   } }); 

Try the above, and do the following which worked for me.

Login to https://www.google.com/settings/security/lesssecureapps and TURN ON Access for less secure apps.

I hope it will work for you too.

Thank you.

like image 150
pavani sri Avatar answered Sep 23 '22 00:09

pavani sri