• 欢迎访问开心洋葱网站,在线教程,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站,欢迎加入开心洋葱 QQ群
  • 为方便开心洋葱网用户,开心洋葱官网已经开启复制功能!
  • 欢迎访问开心洋葱网站,手机也能访问哦~欢迎加入开心洋葱多维思维学习平台 QQ群
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏开心洋葱吧~~~~~~~~~~~~~!
  • 由于近期流量激增,小站的ECS没能经的起亲们的访问,本站依然没有盈利,如果各位看如果觉着文字不错,还请看官给小站打个赏~~~~~~~~~~~~~!

Django发送邮件的代码

Linux 水墨上仙 1537次浏览

CentOS 6.3下使用smtp以及Django 1.4.1发送邮件例子
mail -s “邮件主题”abc@gmail.com < "邮件内容"
使用Django在进行邮件发送
来源:http://blog.csdn.net/willierstrong/article/details/8204794

from django.core.mail import send_mail, BadHeaderError
from django.http import HttpResponseRedirect
def send_email(request):
    subject = request.POST.get('subject', 'this is subject') #发送的邮件主题
    message = request.POST.get('message', 'it \'s time to go home') #发送的消息
    from_email = request.POST.get('from_email', '******') #发件人邮箱
    to_email = request.POST.get('to_email', '××××××')
#收件人的邮箱
    if subject and message and from_email:
        try:
            send_mail(subject, message, from_email, [to_email]) #最后一个参数是收件人列表,可发送至多人
        except BadHeaderError:
            return HttpResponse('Invalid header found.')
        return HttpResponseRedirect('/buy/')
    else:
        # In reality we'd use a form class
        # to get proper validation errors.
        return HttpResponse('Make sure all fields are entered and valid.')


喜欢 (0)
加载中……