# 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 = 'youmail@qq.com' 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', 'you@qq.com', ['to@qq.com'],) 1
遇到的错误:
SMTPAuthenticationError: (502, b'Error: command not implemented')
原因:
smtp密码错误。
其他设置可以参考:https://docs.djangoproject.com/en/dev/topics/email/