web.py 0.3 新手指南 - 发送邮件

问题

在web.py中,如何发送邮件?

解法

在web.py中使用web.sendmail()发送邮件.

web.sendmail('cookbook@webpy.org', 'user@example.com', 'subject', 'message')

如果在web.config中指定了邮件服务器,就会使用该服务器发送邮件,否则,就根据/usr/lib/sendmail中的设置发送邮件。

web.config.smtp_server = 'mail.mydomain.com'

如果要发送邮件给多个收件人,就给to_address赋值一个邮箱列表。

web.sendmail('cookbook@webpy.org', ['user1@example.com', 'user2@example.com'], 'subject', 'message')

ccbcc关键字参数是可选的,分别表示抄送和暗送接收人。这两个参数也可以是列表,表示抄送/暗送多人。

web.sendmail('cookbook@webpy.org', 'user@example.com', 'subject', 'message', cc='user1@example.com', bcc='user2@example.com')

headers参数是一个元组,表示附加标头信息(Addition headers)

web.sendmail('cookbook@webpy.org', 'user@example.com', 'subject', 'message',
        cc='user1@example.com', bcc='user2@example.com',
        headers=({'User-Agent': 'webpy.sendmail', 'X-Mailer': 'webpy.sendmail',})
        )

转载于:https://www.cnblogs.com/justjavac/archive/2012/11/23/webpy-cookbook-sendmail.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值