使用python smtplib通过office365发送电子邮件时,无法解析正常电子邮件地址

2024-06-20 15:04:23 发布

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

我正在尝试使用python发送电子邮件,下面是我的基本代码:

mail_host = MAIL_HOST
mail_user = MAIL_USER
mail_pass = MAIL_PASS
mail_postfix = MAIL_POSTFIX
self.server = smtplib.SMTP(mail_host, port=MAIL_PORT)
self.server.ehlo()
self.server.starttls()
self.server.login(mail_user + "@" + mail_postfix, mail_pass)
self.my_name = MAIL_DISPLAY_SENDER
self.my_addr = self.my_name+"<"+mail_user+"@"+mail_postfix+">"
self.server.sendmail(self.my_addr, "liping.zhang@cimc.com", message.as_string())

然后我得到了这个错误:

smtplib.SMTPDataError: (554, b'5.2.0 STOREDRV.Submission.Exception:InvalidRecipientsException; Failed to process message due to a permanent exception with message Recipient "liping.zhang@cimc.com" isn\'t resolved. All recipients must be resolved before a message can be submitted. InvalidRecipientsException: Recipient "liping.zhang@cimc.com" isn\'t resolved. All recipients must be resolved before a message can be submitted. [Hostname=HK2PR01MB3123.apcprd01.prod.exchangelabs.com]')

这里发生了什么事?我的代码有什么问题吗

谢谢


Tags: 代码selfcommessageservermymailbe