node.js 错误:连接 ECONNREFUSED 127.0.0.1:465 nodemailer
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/38024428/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Error: connect ECONNREFUSED 127.0.0.1:465 nodemailer
提问by Nuru Salihu
I was using my gmail account to send an smtp alert messages to my users email . Example, registration or account blocked etc. I am using a nodemailer and was email were sent successfully without a single failure. Below is my code .
我正在使用我的 gmail 帐户向我的用户电子邮件发送 smtp 警报消息。例如,注册或帐户被阻止等。我正在使用 nodemailer 并且电子邮件已成功发送,没有一次失败。下面是我的代码。
var nodemailer = require("nodemailer");
// create reusable transport method (opens pool of SMTP connections)
var smtpTransport = nodemailer.createTransport("SMTP",{
service: "Gmail",
auth: {
user: "[email protected]",
pass: "userpass"
}
});
// setup e-mail data with unicode symbols
var mailOptions = {
from: "Fred Foo ? <[email protected]>", // sender address
to: "[email protected], [email protected]", // 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
});
Just yesterday , signup for google for business account to my @mydomain account, then replace gmail with my new google for business email that is
就在昨天,将 google for business 帐户注册到我的 @mydomain 帐户,然后将 gmail 替换为我的新 google for business 电子邮件
var smtpTransport = nodemailer.createTransport("SMTP",{
service: "Gmail",
auth: {
user: "[email protected]",
pass: "userpass"
}
});
The problem is, it does not send the email with new account. It rather returned the titled error on my console. I tried change the security of my new account to allow less secure apps from the google console all to no avail. Please what does this error implies? Also considering the user name and pwd for my email are used, is that the best option ? Please how is best achieved ? Any help would be appreciated.
问题是,它不会使用新帐户发送电子邮件。它反而在我的控制台上返回了标题错误。我尝试更改我的新帐户的安全性以允许来自谷歌控制台的安全性较低的应用程序都无济于事。请问这个错误是什么意思?还要考虑使用我的电子邮件的用户名和密码,这是最好的选择吗?请如何最好地实现?任何帮助,将不胜感激。
回答by Nuru Salihu
Thank you for your time guys. Below is what works for me .
谢谢你们的时间。以下是对我有用的内容。
nodemailer.createTransport('smtps://user%myDomain.com:[email protected]');
changed to
变成
var smtpConfig = {
host: 'smtp.gmail.com',
port: 465,
secure: true, // use SSL
auth: {
user: '[email protected]',
pass: 'pass@pass'
}
};
var transporter = nodemailer.createTransport(smtpConfig);
I Found the example above on the doc https://github.com/nodemailer/nodemailer. I am suspecting this may happened to you if your password contained @symbol considering u and the smtps link. Its therefore advisable to split it into an object without the @ symbol interfering with your smtps url. This is my guess thought. Nonetheless the above solution works for me. Plus don't forget to allow less secure apps from your google console.
我在文档https://github.com/nodemailer/nodemailer上找到了上面的示例。我怀疑如果您的密码包含@符号,考虑到您和 smtps 链接,这可能会发生在您身上。因此,建议将其拆分为一个对象,而@ 符号不会干扰您的 smtps url。这是我的猜测。尽管如此,上述解决方案对我有用。另外不要忘记从您的谷歌控制台允许安全性较低的应用程序。
回答by Zach Gollwitzer
Adding a config for Bluehost for anyone using it.
为使用它的任何人添加 Bluehost 的配置。
let transporter = nodemailer.createTransport({
host: 'box1109.bluehost.com',
port: 465,
secure: true,
auth: {
user: '[email protected]',
pass: 'yourpassword'
}
});
You can verify the options using the verify()method.
您可以使用该verify()方法验证选项。
transporter.verify((err, success) => {
if (err) console.error(err);
console.log('Your config is correct');
});
If you are experiencing this error, make sure that the host property is set properly.
如果您遇到此错误,请确保正确设置了主机属性。
console.log(transporter.options.host);
I spent 20 minutes on this error to find out that the host property was undefined (I was using an environment variable to port it into the config).
我在这个错误上花了 20 分钟才发现主机属性未定义(我使用环境变量将其移植到配置中)。

