【发布时间】:2020-02-10 21:16:46
【问题描述】:
我正在尝试使用 nodemailer 发送 gmail。 这是我的代码。
var transporter = nodemailer.createTransport({
service: 'gmail',
auth: {
user: '<sender@gmail.com>',
pass: '<password>'
}
});
var mailOptions = {
from: '<sender@gmail.com>',
to: '<receiver@gmail.com>',
subject: 'Sending Email using Node.js',
text: 'That was easy!'
};
transporter.sendMail(mailOptions, function(error, info){
if (error) {
console.log(error);
} else {
console.log('Email sent: ' + info.response);
}
});
但我总是遇到这个错误。
{ Error: Connection timeout
at SMTPConnection._formatError (E:\Work\Web\GatherSense\gather-sense-backend\node_modules\nodemailer\lib\smtp-connection\index.js:771:19)
at SMTPConnection._onError (E:\Work\Web\GatherSense\gather-sense-backend\node_modules\nodemailer\lib\smtp-connection\index.js:757:20)
at Timeout._connectionTimeout.setTimeout (E:\Work\Web\GatherSense\gather-sense-backend\node_modules\nodemailer\lib\smtp-connection\index.js:229:22)
at ontimeout (timers.js:436:11)
at tryOnTimeout (timers.js:300:5)
at listOnTimeout (timers.js:263:5)
at Timer.processTimers (timers.js:223:10) code: 'ETIMEDOUT', command: 'CONN' }
我花了很多时间并尝试了多种方式,例如允许安全性较低的应用程序和关闭防火墙。 但总是得到同样的错误。请帮助我,谢谢。
【问题讨论】:
-
感谢您的回复。但你的意思是哪个答案有帮助?
-
荒谬的问题。它不能在本地运行,但在云服务器上运行良好。我现在很好。
标签: javascript node.js express smtp nodemailer