如何使用 smtplib SMTP.sendmail 发送邮件后获得服务器回复
我有一个使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您在
SMTP 上使用 sendmail 方法
实例,然后它将返回如果您在同一个类上使用 docmd 方法,则它会回来
If you are using the sendmail method on an
SMTP
instance, then it will returnif you use the docmd method on the same class, the it will return