根路由下配置
MAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.qq.com'
EMAIL_HOST_USER = '66897079@qq.com'
EMAIL_HOST_PASSWORD = 'aavlzhzvqorbcahc'
EMAIL_PORT = 465
EMAIL_USE_SSL = True
发送邮件
message = "<p>尊敬的用户您好:</p><p>欢迎注册达达商城。</p>"
from django.core.mail import send_mail
send_mail(
subject="Subject",
message=None,
from_email='66897079@qq.com',
recipient_list=['66897079@qq.com'],
html_message=message
)
另外
message可以用render_to_string渲染
此时,需要添加templates配置
TEMPLATES = [
{
.......
'DIRS': [BASE_DIR / 'templates'],
......
}
]