Nodemailer: ECONNREFUSED

独自空忆成欢 提交于 2019-11-27 15:33:32

It was a firewall issue. Turns out there was nothing wrong with the code, I just didn't understand what the error message implied.

Following step:

  1. Login gmail account.

  2. Enable pop3 in settings tabs

  3. Enable less secure apps at: Enable less secure apps for gmail account

  4. Display Unlock Captcha at: Display unlock Captcha

  5. Defined email option and sending

    var mailOptions = {
        host: 'smtp.gmail.com',
        port: 465,
        secure: true, // use SSL
        auth: {
            user: 'gmail_account@gmail.com',
            pass: 'password'
        }
    }    
    
    mailer = nodemailer.createTransport(mailOptions);
    
    mailer.sendMail({
    ....
    }, function(err, response) {
            if (err) {
                 console.log(err);
            }
            console.log(response);
    });
    

Hope this block code help you.

I was also using a gmail account to send the email, you might need an Application-specific password from google to allow nodemailer to work properly.

https://support.google.com/mail/answer/1173270?hl=en

ECONNREFUSED inidcates that this is some kind of connection or firewall issue.

Can you connect to smtp.gmail.com port 465 with any other application from the same machine, for example with openssl?

openssl s_client -connect smtp.gmail.com:465
boneyao

if you use new nodemailer version

nodemailer.createTransport({
    host,
    port,
    secure:,
    auth:{
        user,
        pass
    }
})

more see https://github.com/andris9/nodemailer-wellknown

In my case I just had to disable my anti virus, Avast.

To white list on avast do this:

These steps may vary according to your Avast version, including the IP used here

1) Open Avast, go to: Menu -> Settings. (It is located on the top right corner)

2) Go to General Tab -> Exceptions -> Add Exception

3) Get the IP of your gmail, it is going to be with the error, I think.

4) Now paste the IP on your exception

Hope it helps.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!