4

I using below configuration for sending an email via Nodemailer but unable to send it and it is thrown error: getaddrinfo ENOTFOUND ssl://smtp.googlemail.com ssl://smtp.googlemail.com:587 at GetAddrInfoReqWrap.onlookup

Configuration:

host: 'smtp.gmail.com',
port: 465,
secure: true,
auth: {
    user: 'xxx@gmail.com',
    pass: 'xxxx'
}

enter image description here

Anyone can give me a solution to solving it soon?

Kamlesh
  • 654
  • 8
  • 21

4 Answers4

6

Try to add service parameter with value gmail.

var smtpTransport = nodemailer.createTransport({
    service: 'gmail',
    port: 8000,
    secure: false, // use SSL
    auth: {
        user: 'user@gmail.com',
        pass: 'pass'
    }
});

Refer How to send mail using nodemailer

Shivani Sonagara
  • 1,299
  • 9
  • 21
1

Note : make sure you have allowed less security into the following link :

https://myaccount.google.com/security?pli=1#connectedapps

and then configure nodemailer like this :

var smtpTransport = nodemailer.createTransport({
    host: 'smtp.gmail.com',
    port: 465,
    secure: true, // use SSL
    auth: {
        user: 'user@gmail.com',
        pass: 'pass'
    }
});
1

you need to do two things : 1. Add your service provider name

 let transporter = nodemailer.createTransport({
    service: 'gmail',
    port: 25,
    secure: false,
    auth: {
           user: 'your_mail_address@gmail.com',
           pass: 'pass'
         }
    });
  1. set the Access for less secure apps setting to Enable.

Refer to these links:

  1. https://www.w3schools.com/nodejs/nodejs_email.
  2. https://devanswers.co/allow-less-secure-apps-access-gmail-account/
Raj Kumar
  • 31
  • 3
1
This works for me. 

var transporter = nodemailer.createTransport({
   host: 'smtp.gmail.com',
   port: 465,
   secure: true,  
   service: 'Gmail',
   auth: {
    user: 'user@gmail.com',
    pass: '***'
   }
});

var mailOptions = {
  from: SOURCE_EMAIL,
  to: to,
  subject: 'send mail',
  text: 'Your text is here'
};
var status = transporter.sendMail(mailOptions, function(error, info){
   console.log('info...',info);
   if (error) {
      console.log(error);       
   } else {
      console.log('Email sent: ' + info.response);      
  }
});