我正在尝试使用Nodemailer发送一封或批量电子邮件,但在发送电子邮件失败时遇到问题需要处理。未找到电子邮件地址。在尝试两次发送电子邮件后,我需要这些退回电子邮件和其他此类故障的列表并将其插入到数据库中。
以下是我的代码:
const nodemailer = require("nodemailer");
var smtpConfig = nodemailer.createTransport(
{
host: hostname,
port: port,
secure: false,
auth: {
user: username,
pass: password
},
logger: false,
debug: false
},
{
headers: [],
priority: "normal"
}
);
function sendMailnew() {
const mailOptions = {
from: "email.com,
to: "sjdhf@jhdf.com",
subject: "my testing emails new",
html: "my testing email",
dsn: {
id: "123",
return: "HEADERS",
notify: ["failure", "delay"],
recipient: "abc@gmail.com"
}
};
smtpConfig.sendMail(mailOptions, function(error, response) {
if (error) {
console.log(error);
} else {
console.log("mail sent");
}
});
}
sendMailnew();
我正在使用gmail SMTP。请帮助。谢谢!如果需要更多细节,请告诉我。