import yagmail
#创建链接自己的邮箱服务器的对象,user:邮箱名字, password:邮箱授权码, host:smtp邮箱地址
yag = yagmail.SMTP(user="sender@126.com", password="126邮箱授权码", host='smtp.126.com')
#邮箱正文,列表中的第一项是body,第二项是html,第三项是图片地址,当然了contents也可以是字符串
contents = ['This is the body, and here is just text http://somedomain/image.png',
'<a href="https://pypi.python.org/pypi/sky/">Click me!</a>', '/local/path/song.mp3']
# 邮件主题
subject = 'subject'
# 发送邮件, 接收人邮箱 邮件主题 邮件正文
yag.send('receiver@qq.com', subject, contents)
# 给多个收件人发送邮件
yag.send(['receiver1@qq.com', 'receiver2@qq.com', 'receiver3@qq.com'], subject, contents)
# 发送带附件的邮件, file_list是一个列表,里面每一项是发送的文件的本地路径
file_list = ["C://1.txt", "E://2.jpg"]
yag.send('receiver@qq.com', subject, contents, file_list)
python第三方发送邮件库yagmail的使用总结
最新推荐文章于 2024-06-20 04:30:00 发布