gpt4 book ai didi

node.js - 如何使用 nodemailer SES 传输正确限制消息发送?

转载 作者:搜寻专家 更新时间:2023-10-31 23:26:17 24 4
gpt4 key购买 nike

The nodemailer documentation说:

If you use rate or connection limiting then you can also use helper methods to detect if the sending queue is full or not. This would help to avoid buffering up too many messages.

它还提供了一个例子:

let transporter = nodemailer.createTransport({
SES: new aws.SES({
apiVersion: '2010-12-01'
}),
sendingRate: 1 // max 1 messages/second
});

// Push next messages to Nodemailer
transporter.on('idle', () => {
while (transporter.isIdle()) {
transporter.sendMail(...);
}
});

不幸的是,这对我来说相当神秘。 sendingRate: 1 只提供帮助程序,还是处理节流?

此外,这段代码在我看来会在 sendMail(...) 执行后无限循环。我在这里遗漏了什么吗?

有没有关于如何使用此功能的示例或建议?

非常感谢!

最佳答案

来自documentation :

SES can tolerate short spikes but you can’t really flush all your emails at once and expect these to be delivered. To overcome this you can set a rate limiting value and let Nodemailer handle everything – if too many messages are being delivered then Nodemailer buffers these until there is an opportunity to do the actual delivery.

我不认为监听 idle 事件是强制性的,只有当你想避免 Nodemailer 缓冲消息时才需要它。我的 SES 发送速率为每秒 15 条消息,并定期在 Nodemailer 上一次发送 250 封电子邮件,并且没有遇到任何限制问题。

关于node.js - 如何使用 nodemailer SES 传输正确限制消息发送?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48338564/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com