settings配置
#########
# EMAIL #
#########
# EMAIL_HOST = "smtp.exmail.qq.com"
# EMAIL_PORT = 465
EMAIL_HOST = "smtp.163.com"
EMAIL_PORT = 25
EMAIL_HOST_USER = "zhangziyi185x@163.com"
# xvazehafbcbjbifd ysvnktnxiocrcaih
# EMAIL_HOST_PASSWORD = "cqnqiizhfioubjfd"
EMAIL_HOST_PASSWORD = "***********"
DEFAULT_FROM_EMAIL = EMAIL_HOST_USER
# EMAIL_USE_SSL = True
EMAIL_SUBJECT_PREFIX = "[初始一梦] "
# 默认邮件接收方(开发人员,如果代码出现极端异常可进行邮件通知.)
DEFAULT_TO_EMAILS = [
"379703108@qq.com",
]
# 配置读写分离
# DATABASE_ROUTERS = [
# 'utils.db_router.MasterSlaveDBRouter'
# ]
路由发送邮件
def send_mail(request):
"""
发送邮件
前提:请在配置文件中配置邮箱属性
"""
# from django.core.mail import send_mail
# 关于更多邮件客户端可使用
from django.core.mail import EmailMultiAlternatives
msg = EmailMultiAlternatives(
"邮件标题", "邮件内容", from_email=settings.DEFAULT_FROM_EMAIL, to=["379703108@qq.com", ]
)
# 如果发送内容为`html`格式的话, 设置这个属性即可
msg.content_subtype = "html"
msg.send()
# 如果发送内容为`html`格式的话, 多传 `html_message`
# result = send_mail(
# "你好", "世界", "18803561683@163.com", ["404042726@qq.com", ],
# )
# print(result)
return HttpResponse("Ok")