python Django 发送邮件

发送邮件

from django.core.mail import send_mail
from django.conf import settings

# 获取配置信息
from_email = settings.DEFAULT_FROM_EMAIL
send_mail("Django", "This Django", from_email, ['123456@qq.com'])

from django.core.mail import send_mass_mail

# 发送多篇邮件
message1 = ("D1", "title 1", from_email, ['123456@qq.com'])
message2 = ("D2", "title 2", from_email, ['654321@qq.com'])
send_mass_mail((message1, message2), fail_silently=False)

from django.core ・mail import EmailMultiA丄ternatives 
content = '<p> 这是一封 <strong> 重要的 v/strong> 邮件。</p>'
msg = EmailMultiAlternatives('MyDjango', content, from_email, ['554301449@qq・com'])
# 将正文设置为HTML格式
msg.content_subtype = 'html' 
# attach_alternative对正文内容进行补充和添加
msg.attach_alternative('<strong>This is from Django</strong>', 'text/html')
# 添加附件(可选)
msg.attach_file('./attachfile.csv')
# 发送
msg.send()
原文地址:https://www.cnblogs.com/iFanLiwei/p/13408721.html