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

2024-10-01 15:40:03 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个使用pythonsmtplib发送邮件的程序。我的邮件发送部分工作正常,但我还需要捕获服务器返回消息后,邮件已发送。例如,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),我可以打印这些文件,但是我需要在一个变量中捕获它,以便进一步记录和处理。在

谢谢和问候

拉吉


Tags: 程序消息dataas邮件okmsgreply
1条回答
网友
1楼 · 发布于 2024-10-01 15:40:03

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

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.

如果在同一个类上使用docmd方法,它将返回

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

相关问题 更多 >

    热门问题