1、settings.py 增加Email设置
#mail
EMAIL_HOST = ‘smtp.gmail.com’ #邮件smtp服务器
EMAIL_PORT = ’25′ #端口
EMAIL_HOST_USER = ‘code***@gmail.com’ #邮件账户
EMAIL_HOST_PASSWORD = ‘*********’ #密码
EMAIL_USE_TLS = False
2、views.py 发送邮件
from django.core.mail import EmailMultiAlternativesfrom django.template import loaderfrom settings import EMAIL_HOST_USERimport threadingfrom_email = EMAIL_HOST_USERclass EmailThread(threading.Thread):def __init__(self, subject, body, from_email, recipient_list, fail_silently, html):self.subject = subjectself.body = bodyself.recipient_list = recipient_listself.from_email = from_emailself.fail_silently = fail_silentlyself.html = htmlthreading.Thread.__init__(self)def run (self):msg = EmailMultiAlternatives(self.subject, self.body, self.from_email, self.recipient_list)if self.html:msg.attach_alternative(self.body,self.html)msg.send(self.fail_silently)def send_mail(subject, body, from_email, recipient_list, fail_silently=False, html=None, *args, **kwargs):EmailThread(subject, body, from_email, recipient_list, fail_silently, html).start()def test_mail(request):subject = u'邮件主题'to_mail_list = ['abc@gmail.com','test@qq.com']body = loader.render_to_string('mail_template.html',{'email':email,'date':datetime.today(), })send_mail(subject,body,from_email,to_mail_list,html="text/html")return "ok"
【IOC框架】分析与理解
【待续】【HTML5】用Canvas标签创建第一张条线图
【转】大型网站后台架构的演变
初探Visual C# SQL CLR Database Project
Js中 关于top、clientTop、scrollTop、offsetTop
JS的正则表达式
jquery的extend和fn.extend
C/C++版数据结构之链表<三>
C/C++ 一点笔记(2)