django使用smtp发送邮件

# cat settings.py
...
...
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'

EMAIL_USE_SSL = True
EMAIL_HOST = 'smtp.qq.com'
EMAIL_PORT = '465'
EMAIL_HOST_USER = '[email protected]'
EMAIL_HOST_PASSWORD = 'passwd'
EMAIL_TIMEOUT = 60

启用SSL安全链接。网上看到说是启用TLS,我这边试了不行(django 1.11)。

>>> from django.core.mail import send_mail
>>> send_mail('Subject here', 'Here is the message', '[email protected]', ['[email protected]'],)
1

遇到的错误:

    SMTPAuthenticationError: (502, b'Error: command not implemented')

    原因:

        smtp密码错误。


其他设置可以参考:https://docs.djangoproject.com/en/dev/topics/email/

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章