我使用nodemailer发送多封电子邮件,他们的内容电子邮件在一起是不同的。它有错误
数据命令失败: 421 4.3.0临时系统问题。稍后再试(10)
这是我的代码
notices.forEach((notice) => {
const now = Date.now();
const schedule = new Date(notice.scheduleDate).getTime();
if (schedule <= now) {
// 2. send email to customer
const customers = notice.customers;
customers.forEach((customer) => {
let fsResetpwdTemp = fs.readFileSync(
path.join(
_baseDir,
_staticDir,
"/templates/voc-notification-template.html"
),
{ encoding: "utf-8" }
);
fsResetpwdTemp = fsResetpwdTemp.replace(
"[toEmail]",
customer.email
);
fsResetpwdTemp = fsResetpwdTemp.replace("[title]", "SASE Notice");
fsResetpwdTemp = fsResetpwdTemp.replace(
"[content]",
notice.contents
);
const mailOptions = {
from: fastify.config.USER_MAIL,
to: customer.email,
subject: notice.title,
html: fsResetpwdTemp,
};
listMailOptions.push(mailOptions);
// Utils.sendMail(mailer, mailOptions);
});
// 3. notify to customer portal
const notification = {
customers,
title: notice.title,
contents: notice.contents,
answeredBy: notice.createdBy,
scheduleDate: notice.scheduleDate,
type: "Notification",
};
for (let client of fastify.websocketServer.clients) {
client.send(JSON.stringify(notification));
}
const bodyUpdate = {
status: NOTICE.STATUS.SENT,
id: notice.id,
};
fastify.axios.put(
fastify.config.QUARKUS_ENDPOINT + `/api/notice/update-by-id`,
bodyUpdate
);
}
});
for (const mailOption of listMailOptions) {
await Utils.sendMail(mailer, mailOption);
}
reply.status(200).send({ data: req.locales["SEND_NOTIFICATION_DONE"] });
} catch (error) {
reply.status(9999).send(error);
}你能帮我解决吗?
发布于 2022-12-02 09:55:09
要用Node.js发送大量电子邮件,您需要执行以下操作:
在计算机上安装Node.js电子邮件库,如Nodemailer。该库将提供必要的工具和功能,以发送电子邮件与Node.js。
将电子邮件库导入到您的Node.js脚本中,并使用电子邮件服务器设置(如服务器主机名、端口号和身份验证详细信息)对其进行配置。
创建一个函数或脚本来生成和发送电子邮件给您的收件人。此功能应以电子邮件地址和电子邮件内容的列表作为输入,并应使用电子邮件库发送电子邮件。
如果您正在发送大量电子邮件,则可能需要使用循环或其他控制结构来迭代收件人列表并分批发送电子邮件。这有助于避免在一次发送大量电子邮件时可能发生的超时或其他错误。
测试您的脚本或功能,以确保它是正确的电子邮件发送。您可以通过向自己或其他收件人发送一些测试邮件来验证电子邮件是否按预期发送和接收。
一旦您的脚本或功能正确工作,您可以使用它来发送大量电子邮件给您的收件人。
总的来说,使用Node.js发送大量电子邮件涉及使用Node.js电子邮件库,使用电子邮件服务器设置配置库,以及创建一个脚本或功能,以生成电子邮件并将电子邮件发送给收件人。通过遵循这些步骤,您可以使用Node.js高效有效地发送大量电子邮件。
https://stackoverflow.com/questions/74653807
复制相似问题