来源: https://answers.microsoft.com/en-us/msoffice/forum/msoffice_outlook-mso_other-mso_o365b/smtp-response-question/efa44b6d-aa47-4d01-84d4-de5d9f733638
错误提示:
smtp.partner.outlook.cn:587
connect: ('smtp.partner.outlook.cn', 587)
connect: ('smtp.partner.outlook.cn', 587)
reply: '220 SH0PR01CA0008.partner.outlook.cn Microsoft ESMTP MAIL Service ready at Tue, 15 Dec 2020 11:25:17 +0000\r\n'
reply: retcode (220); Msg: SH0PR01CA0008.partner.outlook.cn Microsoft ESMTP MAIL Service ready at Tue, 15 Dec 2020 11:25:17 +0000
connect: SH0PR01CA0008.partner.outlook.cn Microsoft ESMTP MAIL Service ready at Tue, 15 Dec 2020 11:25:17 +0000
send: 'ehlo #cet.txxx.cn\r\n'
reply: '501 5.5.4 Invalid domain name [SH0PR01CA0008.CHNPR01.prod.partner.outlook.cn]\r\n'
reply: retcode (501); Msg: 5.5.4 Invalid domain name [SH0PR01CA0008.CHNPR01.prod.partner.outlook.cn]
send: 'helo #cet.txxx.cn\r\n'
reply: '501 5.5.4 Invalid domain name [SH0PR01CA0008.CHNPR01.prod.partner.outlook.cn]\r\n'
reply: retcode (501); Msg: 5.5.4 Invalid domain name [SH0PR01CA0008.CHNPR01.prod.partner.outlook.cn]
[err](501, '5.5.4 Invalid domain name [SH0PR01CA0008.CHNPR01.prod.partner.outlook.cn]')
原因在引用地址中说的很明白了:
Hi Shen,
Thank you for sharing.
From your description, Smtplib adds the sender’s host name to the end of the EHLO command, and Office 365 doesn’t recognize this command. I’d like to let you know that we usually recommend that users use Outlook Web App or Outlook client applications to send emails. Since this problem is caused because Smtplib adds some content to the command and disrupted the email sending process, we suggest you contact Smtplib support to check if they can change the Smtplib’s behavior to avoid this issue.
解决方式:
按上文的思路将这里ehlo后的host地址直接删除就ok了,修改底层库如下:
再次测试通过了,如下:测试代码:
try:
smtp_server = "%s:%s" % (mail_host, mail_port)
print(smtp_server)
s = smtplib.SMTP()
s.set_debuglevel(1)
s.connect(smtp_server)
s.starttls()
s.ehlo()
没有评论:
发表评论