import yagmail
# 链接邮箱服务器
yag = yagmail.SMTP(user="124xxxxx@qq.com", password="gkcooyxxxxxxx", host='smtp.qq.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('lvxxxxxx@xxxxx666.cn','Python email test', contents)"""给多个用户发邮件:
只需要将接收邮箱 变成一个list即可。
"""# 发送邮件# yag.send(['aa@126.com', 'bb@qq.com', 'cc@gmail.com'], 'subject', contents)"""发送附件"""# 发送附件,只要添加一个附件列表就可以了。# yag.send('aaaa@126.com', '发送附件', contents, ["d://log.txt","d://baidu_img.jpg"])"""抄送"""# 邮箱正文 文本及附件
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','测试邮件','test.html','logo.jpg','yagmal_test.txt']# 发送邮件
yag.send(to='xx@xx.com', cc='xxx@xxx.com', subject='发送附件', contents=contents)