即使在运输对象中定义了速率限制,我仍然遇到节流错误。我在哪里缺少?
const nodemailer = require('nodemailer');
const ses = require('nodemailer-ses-transport');
const transporter = nodemailer.createTransport(ses({
accessKeyId: "sesKeys_pub",
secretAccessKey: "sesKeys_pvt",
region : 'us-west-2',
rateLimit: 5
}));
transporter.sendMail({
from: "abc@xyz.com",
to: "abc@xyz.com",
subject: "sample",
html: "<p>html</p>"
}
答案 0 :(得分:0)
您的代码中有错误,应使用sendingRate
文档:https://nodemailer.com/transports/ses/#example-2
const nodemailer = require('nodemailer');
const aws = require('aws-sdk');
const transporter = nodemailer.createTransport(
SES: new aws.SES({
accessKeyId: "sesKeys_pub",
secretAccessKey: "sesKeys_pvt",
region : 'us-west-2',
}),
sendingRate: 5
);
答案 1 :(得分:0)
您需要设置singingRate,然后照常使用sendMail。
transporter = nodemailer.createTransport({
SES: { ses, aws },
sendingRate: 14,
});
const params = {
from: 'EMAIL',
to: 'EMAIL',
subject: 'Message',
html: 'I hope this <b>message</b> gets sent!',
text: 'I hope this message gets sent!',
// attachments: [{ filename: 'card.pdf', content: data, contentType: 'application/pdf' }],
};
transporter.sendMail(params, (err, info) => {
if (err) {
console.log(JSON.stringify(err));
}
console.log(info.envelope);
console.log(info.messageId);
});
这里需要注意的重要一点是,nodemailer 等待下一秒继续处理下一批受限制的电子邮件和下一批,依此类推。因此,如果您运行的脚本在调用最后一个 sendMail() 后立即退出,则将永远不会发送受限制的电子邮件。通过在空闲时侦听或使用 settimeout 来确保该过程一直运行,直到所有电子邮件都发送完毕。