python - Django 无法发送邮件,国内国外各大邮箱都测试无效!
高洛峰
高洛峰 2017-04-17 18:00:27
0
5
591

经测试有 QQ 邮箱
smtp.qq.com 465
smtp.163.com 465/994
smtp.qq.com 465

各种服务和配置方法都试了,例如其中的一种配置方法:
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 465
EMAIL_HOST_USER = 'zmrenwu@gmail.com'
EMAIL_HOST_PASSWORD = 'mypassword'
MAIL_USE_SSL = True

当然,不止以上一种配置,各种服务器,端口号即其排列组合都试了,注册了多个账号测试,账号绝对开启了SMTP/POP3等能开的服务都开了。

然而始终返回如下错误:

raise SMTPServerDisconnected("Connection unexpectedly closed")
    smtplib.SMTPServerDisconnected: Connection unexpectedly closed

django 版本1.9.7,python 3.4

高洛峰
高洛峰

拥有18年软件开发和IT教学经验。曾任多家上市公司技术总监、架构师、项目经理、高级软件工程师等职务。 网络人气名人讲师,...

reply all(5)
小葫芦

Just passed the test using qq mailbox, related configuration:

EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.qq.com'                       #SMTP地址 例如: smtp.163.com
EMAIL_PORT = 25                       #SMTP端口 例如: 25
EMAIL_HOST_USER = ''                  #qq的邮箱 例如: xxxxxx@163.com
EMAIL_HOST_PASSWORD = ''              #我的邮箱密码 例如  xxxxxxxxx
EMAIL_SUBJECT_PREFIX = u'django'       #为邮件Subject-line前缀,默认是'[django]'
EMAIL_USE_TLS = True                  #与SMTP服务器通信时,是否启动TLS链接(安全链接)。默认是false
DEFAULT_FROM_EMAIL = EMAIL_HOST_USER
PHPzhong

In EMAIL_HOST_USER这里填写的是你邮箱的用户名,是zmrenwu才对。然后在设置加入EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'。
另外,在调试模式可以使用MAIL_USE_TLS=True, and bind port 587.

Ty80

I rememberMAIL_USE_SSL这个应该是EMAIL_USE_SSLright?
And sometimes you can try other networks to test. . . It feels like it’s more of a network problem

PHPzhong

gmail is banned!

黄舟

All major domestic mailboxes are accepted.
There is a problem with your configuration, at least ensure the following principles:

  • Use TLS

  • Fill in username and password

  • Enable smtp service on your email provider

The second thing to note is:

  • Don’t send emails too frequently

  • Reject spam

For local configuration, please refer to @mugbya’s answer
For email configuration, please refer to the email instructions

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template