Nodemailer getaddrinfo ENOTFOUND Error

Viewed 26939

Looking for some insight into this error I'm getting.

on smtpTransport.sendmail(func(err, info){})

The err variable returns this:

Error: getaddrinfo ENOTFOUND smtp.gmail.com smtp.gmail.com:465
       at errnoException (dns.js:50:10)
       at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:92:26)

and my code is:

var smtpTransport = nodemailer.createTransport({
                service: 'Gmail',
                auth: {
                    user: 'xxx@gmail.com',
                    pass: 'xxx'
                }
            });
            var mailOptions = {
                to: user.email,
                from: 'xxx@gmail.com',
                subject: 'Node.js Password Reset',
                text: ' '
            };
            smtpTransport.sendMail(mailOptions, function(err) {
            });
        }
    ], function(err) {
    });
2 Answers

Try stop using gmail service and set it up like any other smtpTransport like the following.

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

If This does not work, your server might not be able to lookup smtp.gmail.com due to a firewall or something, to check type the following.

 nslookup smtp.gmail.com

I also faced the same error with aws ses service. In my case it was wrong configuration credentials.

AWS_SES_REGION="us-east-2"
AWS_SES_ACCESS_KEY_ID=""
AWS_SES_SECRET_ACCESS_KEY=""

I updated the AWS_SES_REGION then it worked for me

Related