Nodemailer and Gmail

I would like to send emails using Nodemailer and GMAIL, but that won't work ...

Edit # 1:

Code:

var transporter = nodemailer.createTransport(smtpPool({
  service: 'gmail',
  auth: {
    user: '***@gmail.com',
    pass: '***'
  },
  maxConnections: 5,
  maxMessages: 10
}));

var mailOptions = {
  from: mail, // sender address
  to: 'infoprintwithlove@gmail.com',
  subject: subject,
  text: message,
  html: message
};

transporter.sendMail(mailOptions, function(error, info){
  if(error){
    console.log(error);
  }else{
    request.flash('success', 'Votre message à bien été envoyé.');
    response.redirect('/contacter-printwithlove');
  }
});
      

Run codeHide result


Mistake:

{ [Error: Invalid login]
     code: 'EAUTH',

      

The password seems to be wrong, but on the Gmail web interface my password works fine ...

EDIT # 2:

enter image description here

+3


source to share


1 answer


You need to pass the service = 'gmail' and user / password:

var transporter = nodemailer.createTransport({
  service: 'Gmail',
  auth: {
    user: 'myemail@gmail.com',
    pass: <your password>
  }
});

// Or using SMTP Pool if you need to send a large amount of emails
var smtpPool = require('nodemailer-smtp-pool');
var transporter = nodemailer.createTransport(smtpPool({
  service: 'gmail',
  auth: {
    user: 'myemail@gmail.com',
    pass: <your password>
  },
  maxConnections: 5,
  maxMessages: 10
}));

      



Edit:

You may need to "Allow access to your Google account". Login to your gmail using your browser and then follow this link https://accounts.google.com/DisplayUnlockCaptcha to unblock it. You may need to use the same browser that you just signed in to in order for Google to know which account you want to provide. After clicking the "Allow" button, you should see a message: "Account access is enabled. Please try to sign in to your Google account again from the new device or application."

+2


source







All Articles