我正在使用我的Gmail帳戶向我的用戶電子郵件發送SMTP警報消息。例如,註冊或帳戶被阻止等。我正在使用一個nodemailer,並且沒有發生任何故障就成功發送了電子郵件。以下是我的代碼。錯誤:連接ECONNREFUSED 127.0.0.1:465 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
});
就在昨天
,註冊爲谷歌的商業帳戶我@mydomain帳戶,然後用我的商務電子郵件新的谷歌就是
var smtpTransport = nodemailer.createTransport("SMTP",{
service: "Gmail",
auth: {
user: "[email protected]",
pass: "userpass"
}
});
問題是取代Gmail,它不會發送電子郵件與新帳戶。它反而在我的控制檯上返回了標題錯誤。我試圖改變我的新帳戶的安全性,以允許從谷歌控制檯安全性較低的應用程序都無濟於事。請問這個錯誤意味着什麼?同時考慮到我的電子郵件的用戶名和密碼被使用,那是最好的選擇嗎?請如何最好地實現?任何幫助,將不勝感激。
節點郵件程序顯然試圖連接到本地主機(127.0.0.1),這不太可能是Google的郵件服務器。這意味着運輸環境有問題。試試這個'nodemailer.createTransport('smtps://user%40gmail.com:[email protected]');' – Molda
@Molda感謝您的時間。您的解決方案適用於gmail.com帳戶。當我用'@ mydomain.com'替換電子郵件時失敗。我得到上面的錯誤。我很困惑,我期待它的工作考慮到兩個都是谷歌帳戶。 –
難道你沒有任何機會將smtp.gmail.com更改爲smtp.mydomain.com嗎? – Molda