易于发送邮件的python库
posts的Python项目详细描述
posts是一个易于发送邮件的python库。
示例
这里是第一个用text发送邮件的
posts不仅支持text类型的邮件,还支持html: 接下来,我们可以发送带有附件的邮件: 最后,我们可以发送带有图像的html邮件。和
在本例中,我们还使用alias作为发送方: 也许您需要通过ssl发送邮件,不要担心:frompostsimportPostsmail=Posts('smtp-server','your-username','your-passwd')withmail()asbox:box.text('to_address',subject='Subject',content='Content')
box.html('to_address',subject='Subject',content='Content')
withmail()asbox:box.attach({'example.jpg':'./example.jpg})box.text('to_address',subject='Subject',content='Content')
withmail(alias='alias')asbox:box.attach({'example.jpg':'./example.jpg'})box.html(recipient='to_address',subject='subject',content='<img src="cid:example.jpg">')
withmail(ssl=True)asbox:box.text('to_address',subject='Subject',content='Content')
链条使用量
就这样试试:
box.attach({'name1':'/path/to/file1','name2':'/path/to/file2'}).\ attach({'name3':'/path/to/file3'}).\ text('to_address','subject','content').\ html(['to_address1','to_address2'],'subject','content')
带有附件1,2,3的文本邮件将发送到地址, 然后带有附件1,2,3的HTML邮件将被发送到OT 地址1,地址2在一起。
待办事项
- 为收件人添加别名。
- 添加carbon copy。
- 使用添加不带的用法。