Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nodemailer getaddrinfo ENOTFOUND Error

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: '[email protected]',
                    pass: 'xxx'
                }
            });
            var mailOptions = {
                to: user.email,
                from: '[email protected]',
                subject: 'Node.js Password Reset',
                text: ' '
            };
            smtpTransport.sendMail(mailOptions, function(err) {
            });
        }
    ], function(err) {
    });
like image 837
Ali Malik Avatar asked Sep 22 '17 05:09

Ali Malik


People also ask

How do I fix Getaddrinfo Enotfound?

The error getaddrinfo ENOTFOUND localhost is caused by Webpack cannot found localhost address. To solve it, open the terminal: sudo nano /etc/hosts. Add following into the hosts file and save it.

What does error getaddrinfo ENOTFOUND mean?

getaddrinfo ENOTFOUND means client was not able to connect to given address. Please try specifying host without http: var optionsget = { host : 'localhost', port : 3010, path : '/quote/random', // the rest of the url with parameters if needed method : 'GET' // do GET };


1 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: '[email protected]',
        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
like image 105
Kalana Demel Avatar answered Sep 18 '22 13:09

Kalana Demel