带SMTP后端的django send_mail无法发送电子邮件

时间:2021-12-21 18:14:54

I am deploying a Django project on an ubuntu stack with a postfix SMTP mail server, hosted on Amazon's EC2. I can send out email from the server using the Linux mail program. But when I try to send email using django.core.mail.send_mail, the email is never received.

我正在一个ubuntu堆栈上部署一个Django项目,该服务器上有一个postfix SMTP邮件服务器,托管在亚马逊的EC2上。我可以使用Linux邮件程序从服务器发送电子邮件。但是当我尝试使用django.core.mail.send_mail发送电子邮件时,从未收到该电子邮件。

Here are my settings:

这是我的设置:

EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'

EMAIL_BACKEND ='django.core.mail.backends.smtp.EmailBackend'

I left everything else as default.

我将其他一切都保留为默认值。

I tried

python manage.py shell

python manage.py shell

Then in the shell, I did

然后在shell中,我做到了

from django.core.mail import *
send_mail(
    'TEST',
    'THIS IS A TEST',
    'myemail@domain.com',
    ['toemail@domain.com'],
    fail_silently=False,
    )

This returns 1, but I never received any message at the destination ('toemail@domain.com' in the example).

这返回1,但我从未在目的地收到任何消息(示例中为“toemail@domain.com”)。

Is there a tutorial on how to configure a SMTP server to work with Django's mail system? Thanks.

是否有关于如何配置SMTP服务器以使用Django的邮件系统的教程?谢谢。

1 个解决方案

#1


1  

I assume that you did specify your EMAIL_HOST, EMAIL_PORT, EMAIL_HOST_USER and EMAIL_HOST_PASSWORD in your settings.py right?

我假设你在settings.py中确实指定了你的EMAIL_HOST,EMAIL_PORT,EMAIL_HOST_USER和EMAIL_HOST_PASSWORD吗?

A detailed explanation of how the default django.core.mail.backends.smtp.EmailBackend works is explained - https://docs.djangoproject.com/en/dev/topics/email/ https://docs.djangoproject.com/en/dev/topics/email/#smtp-backend

详细解释了默认django.core.mail.backends.smtp.EmailBackend的工作原理 - https://docs.djangoproject.com/en/dev/topics/email/ https://docs.djangoproject.com/恩的/ dev /主题/电子邮件/#SMTP-后端

And specifically for your email port, you did open your port for smtp under EC2's security group? SMTP port usually defaults to 25 if you left it as default during your postfix configuration and it is important that you have opened up that port when you created your EC2 instance.

特别是对于您的电子邮件端口,您确实在EC2的安全组下打开了smtp端口?如果在后缀配置期间将SMTP端口保留为默认端口,则SMTP端口通常默认为25,并且在创建EC2实例时打开该端口非常重要。

#1


1  

I assume that you did specify your EMAIL_HOST, EMAIL_PORT, EMAIL_HOST_USER and EMAIL_HOST_PASSWORD in your settings.py right?

我假设你在settings.py中确实指定了你的EMAIL_HOST,EMAIL_PORT,EMAIL_HOST_USER和EMAIL_HOST_PASSWORD吗?

A detailed explanation of how the default django.core.mail.backends.smtp.EmailBackend works is explained - https://docs.djangoproject.com/en/dev/topics/email/ https://docs.djangoproject.com/en/dev/topics/email/#smtp-backend

详细解释了默认django.core.mail.backends.smtp.EmailBackend的工作原理 - https://docs.djangoproject.com/en/dev/topics/email/ https://docs.djangoproject.com/恩的/ dev /主题/电子邮件/#SMTP-后端

And specifically for your email port, you did open your port for smtp under EC2's security group? SMTP port usually defaults to 25 if you left it as default during your postfix configuration and it is important that you have opened up that port when you created your EC2 instance.

特别是对于您的电子邮件端口,您确实在EC2的安全组下打开了smtp端口?如果在后缀配置期间将SMTP端口保留为默认端口,则SMTP端口通常默认为25,并且在创建EC2实例时打开该端口非常重要。