django邮件发送
163.com
需要一个邮箱,设置pop3
qq.com
设置setting
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend' EMAIL_HOST = 'smtp.163.com' # EMAIL_USE_TLS = False EMAIL_PORT = 465 EMAIL_USE_SSL = True # 发送邮件的邮箱 EMAIL_HOST_USER = 'peter_KRG@163.com' # 在邮箱中设置的客户端授权密码 EMAIL_HOST_PASSWORD = 'XXXXXX' #qq 163 中的授权码 # 收件人看到的发件人 EMAIL_FROM = '<peter_KRG@163.com>'
设置views
from django_online import settings from django.core.mail import send_mail def send_email_info(): subject = '主题' # 主题 message = 'this is test email' #内容 sender = settings.EMAIL_FROM # 发送邮箱,已经在settings.py设置,直接导入 receiver = ["73197823@qq.com"] # 目标邮箱 html_message = '<h1>%s</h1>' % "我就是有个测试信息" # 发送html格式 send_mail(subject, message, sender, receiver, html_message=html_message)