如何使用 smtplib SMTP.sendmail 发送邮件后获得服务器回复

发布于 2024-09-26 00:46:58 字数 411 浏览 1 评论 0原文

我有一个使用 python smtplib 发送邮件的程序。我的邮件发送部分工作正常,但我还需要在发送邮件后捕获服务器返回消息。例如,在邮件排队后,postfix 返回以下消息:

reply: '250 2.0.0 Ok: queued as EB83821273B\r\n'
reply: retcode (250); Msg: 2.0.0 Ok: queued as EB83821273B
data: (250, '2.0.0 Ok: queued as EB83821273B')

我真正感兴趣的是错误代码 (250) 和队列 ID (EB83821273B)。如果我设置 set_debuglevel(1),我可以打印这些,但我需要将其捕获在变量中以进行进一步的日志记录和处理。

谢谢和问候,

拉杰

I have a program to send mail using python smtplib. I have the mail sending part working fine, but I also need to capture the server return message after a mail has been sent. For example postfix returns the following message after a mail has been queueed:

reply: '250 2.0.0 Ok: queued as EB83821273B\r\n'
reply: retcode (250); Msg: 2.0.0 Ok: queued as EB83821273B
data: (250, '2.0.0 Ok: queued as EB83821273B')

What I am really interested is the error code (250) and the queue id (EB83821273B). I can print these if I set set_debuglevel(1), but I need to capture this in a variable for further logging and processing.

thanks and regards,

raj

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

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

发布评论

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

评论(1

乜一 2024-10-03 00:46:58

如果您在 SMTP 上使用 sendmail 方法 实例,然后它将返回

一本字典,每个字典有一个条目
被拒绝的收件人。每个条目
包含 SMTP 错误的元组
代码和伴随的错误
服务器发送的消息。

如果您在同一个类上使用 docmd 方法,则它会回来

由数字响应代码和实际响应行组成的二元组(多行响应连接成一长行。)

If you are using the sendmail method on an SMTP instance, then it will return

a dictionary, with one entry for each
recipient that was refused. Each entry
contains a tuple of the SMTP error
code and the accompanying error
message sent by the server.

if you use the docmd method on the same class, the it will return

a 2-tuple composed of a numeric response code and the actual response line (multiline responses are joined into one long line.)

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