Python smtplib 和每个连接多条消息
最近我正在研究 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
很有可能。
简单地说,PIPELINING 就是发送 SMTP 命令而不等待响应。它往往不会被实施,因为好处是微乎其微的,而且它增加了错误状态的复杂性。
从您的评论来看,您似乎担心通过一个连接只会发送一封消息。这不是
管道
。smtplib
支持对多条消息使用同一连接。您只需多次调用sendmail
即可。例如最终更新
这在 SMTP 守护程序之间有所不同。 Exim 似乎默认为 1000。
对
sendmail
方法的调用将阻塞直到完成,您的调用将是连续的。如果您需要并行化,那么您可能需要考虑线程、多处理或者扭曲。有许多可能的方法。
允许的并发连接数也可能是 SMTP 守护程序配置项。
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 callsendmail
multiple times. E.g.Final update
This varies between SMTP daemons. Exim seems to default to 1000.
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.