错误:连接ECONNREFUSED 127.0.0.1:465 nodemailer [英] Error: connect ECONNREFUSED 127.0.0.1:465 nodemailer

查看:429
本文介绍了错误:连接ECONNREFUSED 127.0.0.1:465 nodemailer的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用我的gmail帐户向用户的email发送smtp警报消息。例如,注册或帐户被阻止等。我使用的是nodemailer,并且成功发送了电子邮件,没有发生任何故障。下面是我的代码。

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 .

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
});

昨天,将Google商业帐户注册到我的@mydomain帐户,然后用新的gmail替换google

Just yesterday , signup for google for business account to my @mydomain account, then replace gmail with my new google for business email that is

var smtpTransport = nodemailer.createTransport("SMTP",{
    service: "Gmail",
    auth: {
        user: "user@mydomain.com",
        pass: "userpass"
    }
});

问题是,它不使用新帐户发送电子邮件。而是在我的控制台上返回标题错误。我尝试更改新帐户的安全性,以允许安全性较低的Google控制台应用全部无效。请这个错误意味着什么?同时考虑使用我的电子邮件的用户名和密码,那是最好的选择吗?请如何最好地实现?任何帮助将不胜感激。

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.

推荐答案

感谢您的宝贵时间。以下是对我有用的。

Thank you for your time guys. Below is what works for me .

nodemailer.createTransport('smtps://user%myDomain.com:pass@smtp.gmail.com');

已更改为

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

我在文档 https://github.com/nodemailer/nodemailer 。如果您的密码包含 @ 符号(考虑到u和smtps链接),我怀疑这可能发生在您身上。因此,建议将其拆分为一个对象,而@符号不会干扰您的smtps网址。这是我的猜测。尽管如此,以上解决方案仍对我有效。另外,别忘了从您的Google控制台允许安全性较低的应用。

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.

这篇关于错误:连接ECONNREFUSED 127.0.0.1:465 nodemailer的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆