当前位置:  开发笔记 > 编程语言 > 正文

从Python smtplib捕获调试输出

如何解决《从Pythonsmtplib捕获调试输出》经验,为你挑选了0个好方法。

如何捕获Python smtplib库的调试输出?

这是我的测试程序:

import smtplib
s = smtplib.SMTP("mx10.comcast.com")
s.set_debuglevel(1)
s.sendmail("no-such-sender@comcast.com",["no-such-receiver@comcast.com"],"""
from: no-such-sender@comcast.com
to: no-such-receiver@comcast.com
subject: no such message

This message won't be delivered to anybody.
""")

这是输出:

send: 'ehlo dance.local\r\n'
reply: '250-mx10.comcast.com says EHLO to 129.6.220.67:57015\r\n'
reply: '250-SIZE 40000000\r\n'
reply: '250-PIPELINING\r\n'
reply: '250-ENHANCEDSTATUSCODES\r\n'
reply: '250-8BITMIME\r\n'
reply: '250 XXXXXXXA\r\n'
reply: retcode (250); Msg: mx10.comcast.com says EHLO to 129.6.220.67:57015
SIZE 40000000
PIPELINING
ENHANCEDSTATUSCODES
8BITMIME
XXXXXXXA
send: 'mail FROM: size=137\r\n'
reply: '250 2.0.0 MAIL FROM accepted\r\n'
reply: retcode (250); Msg: 2.0.0 MAIL FROM accepted
send: 'rcpt TO:\r\n'
reply: '550 5.1.1 Recipient address rejected: {Gateway}\r\n'
reply: retcode (550); Msg: 5.1.1 Recipient address rejected: {Gateway}
send: 'rset\r\n'
reply: '250 2.0.0 RSET OK\r\n'
reply: retcode (250); Msg: 2.0.0 RSET OK
Traceback (most recent call last):
  File "/Users/simsong/x.py", line 11, in 
    """)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/smtplib.py", line 742, in sendmail
    raise SMTPRecipientsRefused(senderrs)
smtplib.SMTPRecipientsRefused: {'no-such-receiver@comcast.com': (550, '5.1.1 Recipient address rejected: {Gateway}')}

我希望输出为变量output。具体来说,我希望所有以send:和开头的行reply:

推荐阅读
赛亚兔备_393
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有