yagmail是Python的基于GMAIL / SMTP客户端的第三方库,旨在简单发送邮件。对于发送邮件尤其是发送带附件的邮件,没有比这更方便简洁的库了。使用前需先安装。
【注意】必须使用yagmail-0.10.212-py2.py3-none-any.whl,最新版的安装包中文附件时会乱码。本博客亦可提供下载(下载地址https://download.csdn.net/download/cdl3/88516622)。
下面是一段简单的带附件发送的小demo:
import yagmail yag = yagmail.SMTP(user="xxxx@126.com", password="xxxxx", host='smtp.126.com') contents = ['测试邮件内容如下:test mail:', 'This is the body, and here is just text http://somedomain/image.png', 'You can find an audio file attached.', '/local/path/song.mp3']
yag.send('xxxxxxxxx@qq.com', '这是邮件标题(主题)', contents,["d:/应急物品.jpg"]) yag.close()
下篇将给出另外一个第三方库用于发送或者接收邮件,尤其是接收带附件的邮件超级方便(经改造后)。
敬请期待。
【发文章不易,请大家多多点赞、支持!谢谢】
【另外,资源下载栏目也请点击下载一下】