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'])

作者:YangRoc

出处:https://www.cnblogs.com/YangRoc/p/17186555.html

版权:本作品采用「署名-非商业性使用-相同方式共享 4.0 国际」许可协议进行许可。

posted @   Roc-xb  阅读(3)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· winform 绘制太阳,地球,月球 运作规律
· 上周热点回顾(3.3-3.9)

易微帮源码


易微帮官网

more_horiz
keyboard_arrow_up light_mode palette
选择主题
menu
点击右上角即可分享
微信分享提示