search

Home  >  Q&A  >  body text

python - Django 无法发送邮件,国内国外各大邮箱都测试无效!

经测试有 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

高洛峰高洛峰2887 days ago593

reply all(5)I'll reply

  • 高洛峰

    高洛峰2017-04-17 18:02:27

    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

    reply
    0
  • PHPz

    PHPz2017-04-17 18:02:27

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

    reply
    0
  • PHP中文网

    PHP中文网2017-04-17 18:02:27

    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

    reply
    0
  • PHPz

    PHPz2017-04-17 18:02:27

    gmail is banned!

    reply
    0
  • 黄舟

    黄舟2017-04-17 18:02:27

    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

    reply
    0
  • Cancelreply