配置163邮箱
#邮件发送配置
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.163.com'
EMAIL_PORT = 25
#发送邮件的邮箱
EMAIL_HOST_USER = '*******@163.com'
#在邮箱中设置的客户端授权密码
EMAIL_HOST_PASSWORD = '******'
#收件人看到的发件人
EMAIL_FROM = 'python<*****@163.com>' # 需要和邮箱号码一致
配置qq 邮箱
EMAIL_HOST = 'smtp.qq.com'
邮箱
EMAIL_HOST_USER = '*******@qq.com'
授权码
EMAIL_HOST_PASSWORD = '*********'
端口
EMAIL_PORT = 587
EMAIL_USE_TLS = True
EMAIL_FROM = '********@qq.com' 需要和邮箱号码一致
视图函数
from django.core.mail import send_mail
from django.conf import settings
def send_email_demo(request):
from_who = settings.EMAIL_FROM
to_who = 'zhuhaoliang2016@163.com'
subject = '发送一个连接'
message = '点击跳转呵呵呵呵呵呵呵'
send_mail(subject, message, from_who, [to_who], html_message=meg_html)
return HttpResponse("ok")
"""
源码: send_mail 的源码 里面参数很多
def send_mail(subject, message, from_email, recipient_list,
fail_silently=False, auth_user=None, auth_password=None,
connection=None, html_message=None):
"""