我正在尝试使用Office 356邮件服务器从位于数字海洋飞沫上的生产服务器发送电子邮件。
当我在测试服务器(位于我的mac上)上执行python脚本时,该操作可以正确执行,但是在生产服务器上,则代码为500会失败。
我正在使用以下代码来实现这一目标:
def __init__(self, from_address="some@mail.com", from_password="somePassword",
smtp_server="smtp.office365.com", smtp_port=587):
self.from_address = from_address
self.from_password = from_password
self.smtp_server = smtp_server
self.smtp_port = smtp_port
def send_mail(self, recipients, subject, message, project_id, pdf_files):
client_id = ProjectClient.query.filter_by(project_id=project_id).first().client_id
client = Client.query.filter_by(client_id=client_id).first()
server = smtplib.SMTP(self.smtp_server, self.smtp_port)
server.ehlo()
server.starttls()
server.ehlo()
server.login(self.from_address, self.from_password)
...
try:
server.sendmail(self.from_address, recipients, message_body.as_string())
我收到此错误:
File "/usr/lib/python3.5/smtplib.py", line 730, in login
raise last_exception
File "/usr/lib/python3.5/smtplib.py", line 721, in login
initial_response_ok=initial_response_ok)
File "/usr/lib/python3.5/smtplib.py", line 627, in auth
initial_response = (authobject() if initial_response_ok else None)
File "/usr/lib/python3.5/smtplib.py", line 664, in auth_login
raise SMTPAuthenticationError(code, resp)
smtplib.SMTPAuthenticationError: (500, b"5.3.3 Unrecognized command 'cmFwcG9ydEBza2ltbWVsZnJpdC5kaw==' [AM5PR0701CA0011.eurprd07.prod.outlook.com]")
我尝试过的东西
答案 0 :(得分:0)
已通过将python从3.5.0更新到3.5.1(已修复)来解决。