yagmail 实现发邮件

yagmail 实现发邮件

yagmail 可以更简单的来实现自动发邮件功能。

github项目地址: https://github.com/kootenpv/yagmail

安装

pip install yagmail

简单例子

import yagmail

#链接邮箱服务器
yag = yagmail.SMTP( user="[email protected]", password="1234", host='smtp.126.com') # 邮箱正文 contents = ['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('[email protected]', 'subject', contents) 

总共四行代码搞定,是不是比上面的例子简单太多了。

给多个用户发送邮件

# 发送邮件
yag.send(['[email protected]','[email protected]','[email protected]'], 'subject', contents)

只需要将接收邮箱 变成一个list即可。

发送带附件的邮件

# 发送邮件
yag.send('[email protected]', '发送附件', contents, ["d://log.txt","d://baidu_img.jpg"])

只需要添加要发送的附件列表即可。

你可能感兴趣的:(yagmail 实现发邮件)