Unable to send a email using nodemailer - Invalid login error

June 10, 2018 2.4k views
Node.js Email Ubuntu 16.04

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

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 'support@domain.com', I get 'Invalid login' error in the log files.

I use the following code to send the email:

var mail=example@gmail.com;
var code="*******";
var nodemailer = require('nodemailer');

var transporter = nodemailer.createTransport({
      service: 'gmail',
      auth: {
        user: 'support@domainname.com',
        pass: 'password'
    var mailOptions = {
      to: mail,
      subject: 'Verify your account',
      text: 'Veify your account',
        html: " <a href='http://www.domainname.com/verification?code="+code+"'> http://www.domainname.com/verification?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 https://support.google.com/mail/answer/78754

Any help would be appreciated...

Be the first one to answer this question.