首页 > 解决方案 > smtplib.SMTPNotSupportedError:服务器不支持 SMTP AUTH 扩展 - 尝试通过 Django 发送电子邮件

问题描述

我有一个 Docker 容器,我试图通过 Django 发送电子邮件。

我在另一个域上有一个单独的电子邮件服务器,我想将其用于此目的。我有其他应用程序可以毫无问题地连接它。

我的 Django 生产电子邮件设置如下所示(我打算将来用 Kubernetes 机密替换用户名和密码,但为了测试我只是将它们放在文件中):

EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'mail.mydomain.io'
EMAIL_USE_TLS = True
EMAIL_PORT = 587
EMAIL_HOST_USER = "<username>"
EMAIL_HOST_PASSWORD = "<password>"

在我的模块中,我有以下代码:

from rest_framework.views import APIView
from django.core.mail import send_mail

class MailView(APIView):

    def post(self, request):

        subject = request.data.get("subject")
        message = request.data.get("message")
        sender = request.data.get("sender")
        receipients = request.data.get("receipients")

        send_mail(subject,message,sender,receipients,fail_silently=False,)
        ... more

这在本地工作,但是当我尝试在容器内运行它时,我收到以下错误:

smtplib.SMTPNotSupportedError: SMTP AUTH extension not supported by server.

我是否需要在我的 Docker 容器中安装某种 SMTP 中继或服务器?

我的 Docker 容器基于python:3.7容器,我目前没有安装任何 SMTP 扩展或任何东西。

标签: pythondjangodockeremail

解决方案


EMAIL_USE_TLS需要设置为True

EMAIL_USE_TLS = True

推荐阅读