python如何实现实发邮件

这篇文章将为大家详细讲解有关python如何实现实发邮件,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。

yagmail 实现发邮件

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

1、安装

pip install yagmail

2、简单举例

import yagmail

#链接邮箱服务器
yag = yagmail.SMTP( user="user@126.com", password="1234", host='smtp.126.com')

# 邮箱正文
contents = ['This is the body, and here is just text https://cache..com/upload/information/20200622/113/20135.png',
      'You can find an audio file attached.', '/local/path/song.mp3']

# 发送邮件
yag.send('taaa@126.com', 'subject', contents)

3、给多个用户发送邮件

# 发送邮件
yag.send(['aa@126.com','bb@qq.com','cc@gmail.com'], 'subject', contents)

4、发送带附件邮件

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

关于“python如何实现实发邮件”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,使各位可以学到更多知识,如果觉得文章不错,请把它分享出去让更多的人看到。