通过托管的SMTP发送Django的电子邮件

时间:2022-07-11 20:17:15

How do you send email from Django using a hosted SMTP account (specially on Namecheap)?

如何使用托管的SMTP帐户(尤其是Namecheap帐户)从Django发送电子邮件?

I thought this would be straight forward, and simply a matter of filling out the standard EMAIL_* fields in my settings.py.

我认为这将是直接向前的,并且仅仅是填写我的set .py中的标准EMAIL_*字段。

However, after entering my credentials in both my settings.py and Thunderbird, Thunderbird can download and send email, but Django times out with the error "SMTPServerDisconnected: Connection unexpectedly closed" when attempting to do the same.

但是,在两个设置中输入我的凭据之后。py和雷鸟,雷鸟可以下载和发送电子邮件,但Django在尝试执行相同操作时,错误“smtpserverdisconnect: Connection unexpected closed”。

My working settings in Thunderbird for my outgoing server (SMTP):

我的工作设置在雷鸟为我的出站服务器(SMTP):

Server Name: oxmail.registrar-servers.com
Port: 465
User Name: myuser@mydomain.com
Authentication method: Normal password
Connection Security: SSL/TLS

My non-working settings in my Django settings.py:

我在Django设置中的非工作设置。

EMAIL_HOST = 'oxmail.registrar-servers.com'
EMAIL_HOST_USER = 'myuser@mydomain.com'
EMAIL_HOST_PASSWORD = 'mypassword'
EMAIL_PORT = 465
EMAIL_USE_TLS = True
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
DEFAULT_FROM_EMAIL = EMAIL_HOST_USER

Aren't these settings identical? What am I doing wrong? Why does one work while the other fails?

这些设置相同的吗?我做错了什么?为什么一个工作,另一个失败?

2 个解决方案

#1


24  

Turns out the problem was that the default SMTP backend in Django does not support SSL, and my SMTP host required it (not just TLS). Fortunately, I found a dirt-simple SSL backend, added EMAIL_BACKEND = 'django_smtp_ssl.SSLEmailBackend' to my settings.py and everything just worked.

原来问题是Django中的默认SMTP后端不支持SSL,而我的SMTP主机需要它(而不仅仅是TLS)。幸运的是,我找到了一个非常简单的SSL后端,添加了email_background = 'django_smtp_ssl。SSLEmailBackend’我的设置。所有的一切都很顺利。

#2


3  

The settings below:

以下设置:

EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_USE_TLS = True
EMAIL_HOST = 'mail.yourdomain.com'
EMAIL_PORT = 587
EMAIL_HOST_USER = 'no-reply@yourdomain.com'
EMAIL_HOST_PASSWORD = 'password'
DEFAULT_FROM_EMAIL = EMAIL_HOST_USER

worked for me. My django version I tested with is 1.8.8.

为我工作。我测试的django版本是1.8.8。

#1


24  

Turns out the problem was that the default SMTP backend in Django does not support SSL, and my SMTP host required it (not just TLS). Fortunately, I found a dirt-simple SSL backend, added EMAIL_BACKEND = 'django_smtp_ssl.SSLEmailBackend' to my settings.py and everything just worked.

原来问题是Django中的默认SMTP后端不支持SSL,而我的SMTP主机需要它(而不仅仅是TLS)。幸运的是,我找到了一个非常简单的SSL后端,添加了email_background = 'django_smtp_ssl。SSLEmailBackend’我的设置。所有的一切都很顺利。

#2


3  

The settings below:

以下设置:

EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_USE_TLS = True
EMAIL_HOST = 'mail.yourdomain.com'
EMAIL_PORT = 587
EMAIL_HOST_USER = 'no-reply@yourdomain.com'
EMAIL_HOST_PASSWORD = 'password'
DEFAULT_FROM_EMAIL = EMAIL_HOST_USER

worked for me. My django version I tested with is 1.8.8.

为我工作。我测试的django版本是1.8.8。