[英]Nodemailer connection timeout error
我正在使用 nodemailer 模塊從我的 nodejs 應用程序發送郵件。 我收到錯誤:連接 ETIMEDOUT xxx.xxx.xx.xxx:465 。 任何人都可以幫我解決這個問題。 我在這里粘貼我的代碼。
var transporter = nodemailer.createTransport({
service: 'Gmail',
auth: {
user: 'my_mail_id@gmail.com',
pass: 'my_gmail_password'
}
});
console.log('created');
transporter.sendMail({
from: 'my_mail_id@gmail.com',
to: 'my_mail_id@gmail.com',
subject: 'hello world!',
text: 'hello world!'
});
這可能是防火牆問題。 我在 Ubuntu(數字海洋服務器)中遇到了類似的問題。 嘗試解決此問題 3 天,也嘗試使用 auth2,嘗試使用 ufw inactive 命令使用非活動防火牆,但沒有運氣。 最后,我檢查了 Digital Ocean 管理面板並為 droplet 創建了防火牆。 通過在防火牆設置中啟用 TCP 入站和出站解決了問題。
// Create a SMTP transport object
var transport = nodemailer.createTransport("SMTP", {
service: 'Hotmail',
auth: {
user: "username",
pass: "paasweord"
}
});
console.log('SMTP Configured');
// Message object
var message = {
// sender info
from: 'abc@hotmail.com',
// Comma separated list of recipients
to: req.query.to //'aadityashukla9@hotmail.com',
// Subject of the message
subject:req.query.subject //'Nodemailer is unicode friendly ✔',
// plaintext body
text: req.query.text //'Hello to myself!',
// HTML body
/* html:'<p><b>Hello</b> to myself <img src="cid:note@node"/></p>'+
'<p>Here\'s a nyan cat for you as an embedded attachment:<br/></p>'*/
};
console.log('Sending Mail');
transport.sendMail(message, function(error){
if(error){
console.log('Error occured');
console.log(error.message);
return;
}
console.log('Message sent successfully!');
//transport.close(); // close the connection pool
});
我今天遇到了同樣的問題,找到了這個文檔......
https://nodemailer.com/usage/using-gmail/
必須通過在登錄 gmail 時訪問 url 從服務器執行驗證程序。
希望它可以幫助其他人。
此錯誤的唯一原因是:
安全性較低的應用程序:您必須從您的 Gmail 帳戶啟用“安全性較低的應用程序”。
使用 OAuth
除了已經提到的對https://nodemailer.com/usage/using-gmail/信息的引用之外,在我的情況下,Internet 路由器(Speedport W724V)仍然是一個問題。 這會保留所有允許的 SMTP 服務器的列表。 在我相應地擴展了列表之后,它工作得很好。 我必須對smtp.ethereal.email做同樣的事情。
我不確定是否應該發布此答案,但我在使用 GMAIL 時遇到了同樣的問題,而且我的錯誤背后的原因是連接到 vpn。 我禁用了它,現在它可以工作了。
我正在使用應用程序密碼
打開端口入站出站規則 587 或其他,無論您在服務器 aws/google 等上使用哪個。
主機:主機,secureConnection:假,端口:465,安全:真,身份驗證:{用戶:用戶,通過:通過}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.