Channel: CodeSection,代码区,网络安全 - CodeSec
Viewing all articles
Browse latest Browse all 12749



I don't know what I'm missing, I use the Nodemailer example:

var nodemailer = require("nodemailer"); // create reusable transport method (opens pool of SMTP connections) var smtpTransport = nodemailer.createTransport("SMTP",{ service: "Gmail", auth: { user: "gmail.user@gmail.com", pass: "userpass" } }); // setup e-mail data with unicode symbols var mailOptions = { from: "Fred Foo <foo@blurdybloop.com>", // sender address to: "bar@blurdybloop.com, baz@blurdybloop.com", // list of receivers subject: "Hello ", // Subject line text: "Hello world ", // plaintext body html: "<b>Hello world </b>" // html body } // send mail with defined transport object smtpTransport.sendMail(mailOptions, function(error, response){ if(error){ console.log(error); }else{ console.log("Message sent: " + response.message); } // if you don't want to use this transport object anymore, uncomment following line //smtpTransport.close(); // shut down the connection pool, no more messages });

I just changed the user and pass in auth to my gmail account info (also tried with their values), and I changed the "to" email address to my email address. I get:

{ [Error: connect ECONNREFUSED] code: 'ECONNREFUSED', errno: 'ECONNREFUSED', syscall: 'connect' }

What am I missing? I don't see anything in the documentation that says I need to do anything more than this, so why won't it work? Thank you in advance.

Problem courtesy of: user1756980


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

Solution courtesy of: user1756980


if you use new nodemailer version

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

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

Discussion courtesy of: boneyao

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

Discussion courtesy of: Rudolf Olah

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.


Discussion courtesy of: brendecimus

Following step:

Login gmail account.

Enable pop3 in settings tabs

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

Display Unlock Captcha at: Display unlock Captcha

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.

Discussion courtesy of: Dung Vu

This recipe can be found in it's original form on Stack Over Flow .

Viewing all articles
Browse latest Browse all 12749

Latest Images

Trending Articles

Latest Images