当尝试使用 Nodemailer 在 Node 内发送电子邮件时(https://github.com/nodemailer/nodemailer https://github.com/nodemailer/nodemailer),调用sendMail
Nodemailer 传输程序的错误Greeting never received
与 Ethereal 测试电子邮件帐户结合使用时。
我尝试过使用“回调方法”和“异步/等待”方法,但是在两种情况下都会引发相同的错误。这两个示例几乎都直接来自 Nodemailer 文档中的工作示例。也许我错过了一些简单的事情? :)
这是产生错误的“回调方法”代码:
it('can send email with a dynamic test account', done => {
nodemailer.createTestAccount((err, account) => {
const transporter = nodemailer.createTransport({
host: 'smtp.ethereal.email',
port: 587,
auth: {
user: account.user, // generated ethereal user
pass: account.pass // generated ethereal password
}
});
const mailOptions = {
from: '"Fred Foo ????" <[email protected] /cdn-cgi/l/email-protection>', // sender address
to: '[email protected] /cdn-cgi/l/email-protection, [email protected] /cdn-cgi/l/email-protection', // list of receivers
subject: 'Hello ✔', // Subject line
text: 'Hello world?', // plain text body
html: '<b>Hello world?</b>' // html body
};
// send mail with defined transport object
transporter.sendMail(mailOptions, (error, info) => {
if (error) {
return console.log(error);
}
console.log('Message sent: %s', info.messageId);
console.log('Preview URL: %s', nodemailer.getTestMessageUrl(info));
// Message sent: <[email protected] /cdn-cgi/l/email-protection>
// Preview URL: https://ethereal.email/message/WaQKMgKddxQDoou...
done();
});
});
}).timeout(10000);
这是错误的堆栈跟踪:
{ Error: Greeting never received
at SMTPConnection._formatError (/Users/<username>/projects/personal/learning-tests/javascript/nodemailer/node_modules/nodemailer/lib/smtp-connection/index.js:606:19)
at SMTPConnection._onError (/Users/<username>/projects/personal/learning-tests/javascript/nodemailer/node_modules/nodemailer/lib/smtp-connection/index.js:579:20)
at Timeout._greetingTimeout.setTimeout (/Users/<username>/projects/personal/learning-tests/javascript/nodemailer/node_modules/nodemailer/lib/smtp-connection/index.js:520:22)
at ontimeout (timers.js:498:11)
at tryOnTimeout (timers.js:323:5)
at Timer.listOnTimeout (timers.js:290:5) code: 'ETIMEDOUT', command: 'CONN' }
还有一些附加信息:
- 节点版本:
8.11.2
- 节点邮件程序版本:
4.6.4
- 操作系统:
OSX version 10.12.6