【问题标题】:Can't send e-mails using python script on digital ocean droplet无法在数字海洋水滴上使用 python 脚本发送电子邮件
【发布时间】:2019-05-17 14:03:03
【问题描述】:

我正在尝试使用 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]")

我尝试过的东西:

  • 在生产服务器上打开了 587 端口
  • 已联系 Office 支持以将生产服务器 IP 地址添加到受信任列表中

【问题讨论】:

    标签: python-3.x smtp office365 digital-ocean smtp-auth


    【解决方案1】:

    已通过将 python 更新到 3.5.1(从 3.5.0)解决此问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-07
      • 1970-01-01
      • 2019-10-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多