- 当然,但这完全取决于服务器的配置。除非您使用身份验证,否则大多数电子邮件服务器将无法工作。现在是 2017 年
- 好吧,AFAIK nodemailer 根据电子邮件域检测到正确的配置,在您的示例中,您没有设置传输器对象,因此它使用配置的默认端口 25。要更改端口,请在选项中指定类型。我强烈建议您明确指定它。
- 可能是 Windows 防火墙或防病毒软件阻止了传出访问。尝试获取调试/错误消息。我们需要一些东西来帮助你更多。
这是 nodemailer 的新版本,下面是如何使用它的示例:
const nodemailer = require('nodemailer');
// create reusable transporter object using the default SMTP transport
let transporter = nodemailer.createTransport({
host: 'smtp.example.com',
port: 465,
secure: true, // secure:true for port 465, secure:false for port 587
auth: {
user: 'username@example.com',
pass: 'userpass'
}
});
// setup email data with unicode symbols
let 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 ?', // 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 %s sent: %s', info.messageId, info.response);
});
我希望它有所帮助。