django发送邮件

在setting里面添加以下内容
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'

EMAIL_USE_TLS = True#
EMAIL_HOST = 'smtp.sina.com'#新浪邮箱
EMAIL_PORT = 25#端口号
EMAIL_HOST_USER = 'xxx@sina.com'#用户名
EMAIL_HOST_PASSWORD = 'xxx'#密码
DEFAULT_FROM_EMAIL = 'xxx@sina.com'#发送邮箱默认用户名
发送 简单 邮件:
from django.core.mail import send_mail
send_mail('标题','内容','bbaobelief@163.com', ['773889242@qq.com'],fail_silently=True)
发送含有html的邮件:
from django.core.mail import EmailMultiAlternatives
subject = u'标题'
from_email = settings.DEFAULT_FROM_EMAIL
to = str(email)
text_content = u'文本内容'
html_content = u'<b>链接:</b><a href="xx">xx</a>'
msg = EmailMultiAlternatives(subject,text_content,from_email,[to])
msg.attach_alternative(html_content, "text/html")
msg.send()

可以直接使用send_mail函数,详情见另一随笔

原文地址:https://www.cnblogs.com/lgh344902118/p/6039121.html