Python smtplib 和每个连接多条消息

发布于 2024-09-19 08:44:21 字数 146 浏览 2 评论 0原文

最近我正在研究 python 的 smtplib smtp 客户端库,但我找不到任何对支持它的 smtp 服务器的 PIPELINING 协议的引用。 我缺少什么吗?也许还没有实施?除了启用 PIPELINING 的 smtplib 之外,还有其他实现吗?

谢谢

recently i'm studing the smtplib smtp client library for python, but i could not find any reference to the PIPELINING protocol against smtp servers that support it.
Is there something i'm missing? It's not yet implemented maybe? Any other implementations rather than smtplib with PIPELINING enabled?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

凶凌 2024-09-26 08:44:21

我有什么遗漏吗?

很有可能。

简单地说,PIPELINING 就是发送 SMTP 命令而不等待响应。它往往不会被实施,因为好处是微乎其微的,而且它增加了错误状态的复杂性。

从您的评论来看,您似乎担心通过一个连接只会发送一封消息。这不是管道

smtplib 支持对多条消息使用同一连接。您只需多次调用 sendmail 即可。例如

s = smtplib.SMTP("localhost")
s.sendmail("[email protected]",["[email protected]"],message1)
s.sendmail("[email protected]",["[email protected]"],message2)

最终更新

我可以附加“每个连接”的最大消息数是多少?

这在 SMTP 守护程序之间有所不同。 Exim 似乎默认为 1000。

我必须同步执行此操作还是 smtplib 最终会处理当代的 sendmail 调用?

sendmail 方法的调用将阻塞直到完成,您的调用将是连续的。

如果您需要并行化,那么您可能需要考虑线程、多处理或者扭曲。有许多可能的方法。

允许的并发连接数也可能是 SMTP 守护程序配置项。

Is there something i'm missing?

Quite possibly.

Simply put PIPELINING is sending SMTP commands without waiting for the responses. It doesn't tend to be implemented because the benefits are marginal and it increases the complexity of error states.

From your comment, it sounds as if you are worried that only one message will be sent through one connection. This is not PIPELINING.

smtplib supports using the same connection for multiple messages. You can just call sendmail multiple times. E.g.

s = smtplib.SMTP("localhost")
s.sendmail("[email protected]",["[email protected]"],message1)
s.sendmail("[email protected]",["[email protected]"],message2)

Final update

which is the max number of messages i can append "per-connection" ?

This varies between SMTP daemons. Exim seems to default to 1000.

do i have to do this synchronously or does smtplib eventually handle contemporary sendmail calls ?

The call to the sendmail method will block until complete, your calls will be sequential.

If you need to parallelize then you might need to look at threading, multiprocessing or perhaps twisted. There are many possible approaches.

The number of concurrent connections you are allowed may also be an SMTP daemon configuration item.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文