0
点赞
收藏
分享

微信扫一扫

python实现邮件发送功能


用最简单的方法实现邮件发送功能,拒绝重复造轮子,提供工作效率。

目录

​​1、安装依赖​​

​​ 2、发送文本邮件​​

​​3、发送多人邮件​​

​​4、发送附件邮件​​

1、安装依赖

pip install yagmail

 2、发送文本邮件

import yagmail

# 初始化
config = yagmail.SMTP(user='1740837342@qq.com', password='mypassword', host='smtp.qq.com')

# 发送邮件
config.send(to='aida_pc@qq.com', subject='Testing Yagmail', contents='Hello Yagmail!')

3、发送多人邮件

import yagmail

# 初始化
config = yagmail.SMTP(user='1740837342@qq.com', password='mypassword', host='smtp.qq.com')

# 发送多人邮件
config.send(to=['aida_pc@qq.com', 'aida_pc@163.com'],
subject='Testing Yagmail',
contents='Hello Yagmail!')

4、发送附件邮件

只需要在 send() 函数中多设置一个 ​​attachments​​ 参数即可:

import yagmail

# 初始化
config = yagmail.SMTP(user='1740837342@qq.com', password='mypassword', host='smtp.qq.com')

# 发送邮件
config.send(to='aida_pc@qq.com', subject='Testing Yagmail', contents='Hello Yagmail!',attachments=['1.jpg','2.jpg'])

举报

相关推荐

0 条评论