Unable to send a email using nodemailer - Invalid login error

Posted June 10, 2018 11k views
Node.jsEmailUbuntu 16.04

I am relatively new to Node.js and Digitalocean. I have a website hosted on digitalocean - The domain name was registered with GSuite. I want to send a verification email from to a gmail address, say

I tried using the nodemailer module for this. When I try to send an email from my my own gmail address I can send the verification link to any email account. But when I try to send an email from ’’, I get ‘Invalid login’ error in the log files.

I use the following code to send the email:

var code="*******";
var nodemailer = require('nodemailer');

var transporter = nodemailer.createTransport({
      service: 'gmail',
      auth: {
        user: '',
        pass: 'password'
    var mailOptions = {
      to: mail,
      subject: 'Verify your account',
      text: 'Veify your account',
        html: " <a href='"+code+"'>"+code+"  </a> "
    transporter.sendMail(mailOptions, function(error, info){
      if (error) {
      } else {
        console.log('Email sent: ' + info.response);

This is the error message in the log file:

Error: Invalid login.
Please log in via your web browser and then try again.
Learn more at

Any help would be appreciated…

edited by kamaln7

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
3 answers

I have also experienced the same issue earlier today and enabling UnlockCaptcha has resolved this issue, ( try enabling this option to your Gmail account which you’re using in nodemailer.

Hi -
I see this post is old, but I am experiencing the same issue . Any suggestion?

I am also experiencing the same problem. any change we can escalate this?