网络编程
位置:首页>> 网络编程>> Python编程>> python实发邮件实例详解

python实发邮件实例详解

作者:ZibinChen  发布时间:2023-10-13 00:43:01 

标签: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 http://somedomain/image.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"])

来源:https://www.cnblogs.com/zibinchen/p/11834537.html

0
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com