我收到收件人错误:无法发送邮件 - 使用npm节点邮件程序发送电子邮件时没有收件人定义的错误。我正在咨询文档中的示例。用真实的电子邮件考虑abc@gmail.com。
var emailAddress = "abc@gmail.com";
mailOptions = {
from: "Admin <abc@gmail.com>", // sender address
to: emailAddress, // list of receivers
subject: "Hello", // Subject line
text: "hello", // plaintext body
html: "<b>Hello</b>" // html body
}
smtpTransport = nodeMailer.createTransport("SMTP",{
service: "Gmail",
auth: {
user: "abc@gmail.com",
pass: "123"
}
});
smtpTransport.sendMail(mailJson, 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
});
答案 0 :(得分:0)
以下建议对其他用户有用:
mailJson
是您的配置mailOptions
。因此,您的代码如下:
mailOptions = {
from: "Admin <abc@gmail.com>", // sender address
to: emailAddress, // list of receivers
subject: "Hello", // Subject line
text: "hello", // plaintext body
html: "<b>Hello</b>" // html body
}
smtpTransport = nodeMailer.createTransport("SMTP",{
service: "Gmail",
auth: {
user: "abc@gmail.com",
pass: "123"
}
});
return new Promise((resolve, reject) => {
transporter.sendMail(mailOptions, (error, info) => {
error ? reject(error) : resolve(info);
});
});
});
答案 1 :(得分:0)
如果没有适合您的解决方案
转到该链接并激活比尝试发送邮件安全性低的活动 enter link description here