比这篇新的文章: 连庄 vs. 轮庄
比这篇旧的文章: 在新窗口运行HTML代码显示结果的脚本

封装Django的send_mail函数,方便在本地(没有邮件服务器)进行邮件相关的测试

语言: Python, 标签: Django 测试 邮件 2008/10/21发布 8个月前更新 更新记录
作者: 半瓶墨水, 点击754次, 评论(0), 收藏者(0), , 打分:

背景
主题: 字体:
01 def my_send_mail(request, subject, body, sender, recv_list, reply_to=None):
02     """send_mail wrapper: write to command line if it's called on localhost
03     """
04     local = "127.0.0.1"
05     if request.META['HTTP_HOST'][:len(local)] == local:
06         print "Subject:", subject
07         print "From:", sender
08         print "To:", recv_list
09         if reply_to:
10             print "Reply-To:", reply_to
11         print "Body:\n", body
12     else:
13         if reply_to:
14             email = EmailMessage(
15                         subject,
16                         body,
17                         sender,
18                         recv_list,
19                         [],
20                         headers = {'Reply-To': reply_to})
21             email.send()
22         else:
23             send_mail(subject, body, sender, recv_list)


所有评论,共0条:( 我也来说两句)


发表评论

注册登录后再发表评论