【问题标题】:DJango mail working in local but not in productionDJango 邮件在本地工作但不在生产中
【发布时间】:2021-12-05 06:36:34
【问题描述】:

以下是我向我的用户发送邮件的代码:

mail = EmailMultiAlternatives(subject=subject, body=text_content, from_email="email@host.com", to=["email@host.com"], bcc=["email@host.com"])
mail.attach_file(model.document.path)
mail.attach_alternative(html_content, "text/html")
mail_status = mail.send()

我的settings.py如下:

EMAIL_HOST = "mail.host.com"
EMAIL_PORT = 587

EMAIL_HOST_USER = "email@host.com"
EMAIL_HOST_PASSWORD = str(os.getenv('EMAIL_HOST_PASSWORD'))

问题是上面的代码在我的本地 Windows 机器上运行得非常好,但是在运行 Ubuntu (Linux) 的远程服务器上运行时代码挂起并且没有显示输出。

知道我哪里出错了吗?

【问题讨论】:

    标签: python django email smtplib django-email


    【解决方案1】:

    这很可能是端口问题。确认这一点的最佳方法是使用telnet 客户端。

    telnet mail.host.com 587
    

    如果您在发出此命令后没有看到Connected 文本,那么问题很可能是因为port。在这种情况下,您可能需要explicitly open this port

    【讨论】:

      猜你喜欢
      • 2023-03-19
      • 1970-01-01
      • 2021-09-21
      • 2016-02-18
      • 1970-01-01
      • 1970-01-01
      • 2021-06-08
      • 2016-07-16
      • 2018-03-23
      相关资源
      最近更新 更多