Python实现给qq邮箱发送邮件的方法
作者:imzoer 时间:2022-11-16 21:01:21
本文实例讲述了Python实现给qq邮箱发送邮件的方法。分享给大家供大家参考。具体实现方法如下:
#-*-coding:utf-8-*-
#==========================================
# 导入smtplib和MIMEText
#==========================================
from email.mime.text import MIMEText
import smtplib
#==========================================
# 要发给谁,这里发给2个人
#==========================================
mailto_list=["naughty610@qq.com","1034791200@qq.com"]
#==========================================
# 设置服务器,用户名、口令以及邮箱的后缀
#==========================================
mail_host="smtp.qq.com"
mail_user="naughty610"
mail_pass="here is your password"
mail_postfix="qq.com"
#==========================================
# 发送邮件
#==========================================
def send_mail(to_list,sub,content):
'''''
to_list:发给谁
sub:主题
content:内容
send_mail("aaa@126.com","sub","content")
'''
me=mail_user+"<"+mail_user+"@"+mail_postfix+">"
msg = MIMEText(content)
msg['Subject'] = sub
msg['From'] = me
msg['To'] = ";".join(to_list)
try:
s = smtplib.SMTP()
s.connect(mail_host)
s.login(mail_user,mail_pass)
s.sendmail(me, to_list, msg.as_string())
s.close()
return True
except Exception, e:
print str(e)
return False
if __name__ == '__main__':
if send_mail(mailto_list,"here is subject","here is content"):
print "发送成功"
else:
print "发送失败"
希望本文所述对大家的Python程序设计有所帮助。
标签:Python,发送,邮件
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
使链接具有最大化、最小化的功能代码
2008-02-24 16:43:00
python 读取、写入txt文件的示例
2023-09-29 22:04:18
![](https://img.aspxhome.com/file/2023/7/63237_0s.png)
关于go语言编码需要放到src 文件夹下的问题
2023-07-03 07:34:00
![](https://img.aspxhome.com/file/2023/5/86305_0s.png)
python集合比较(交集,并集,差集)方法详解
2023-09-30 22:11:13
python opencv实现图像矫正功能
2022-05-22 17:00:13
![](https://img.aspxhome.com/file/2023/0/107120_0s.jpg)
Python实现绘制双柱状图并显示数值功能示例
2023-12-06 06:31:03
![](https://img.aspxhome.com/file/2023/4/101474_0s.png)
php查询mysql数据库并将结果保存到数组的方法
2023-07-20 17:47:32
无忧贴子管理器(ListView组件)
2009-01-02 17:56:00
python关于矩阵重复赋值覆盖问题的解决方法
2021-12-11 03:07:17
Python 代码性能优化技巧分享
2023-10-15 05:00:56
![](https://img.aspxhome.com/file/2023/3/107203_0s.gif)
2008农历新年各大网站Logo秀
2008-02-11 16:33:00
![](https://img.aspxhome.com/file/UploadPic/20082/11/200821117040777s.jpg)
python微信跳一跳系列之自动计算跳一跳距离
2021-08-01 14:18:36
![](https://img.aspxhome.com/file/2023/3/66813_0s.gif)
python requests.post请求404问题及解决方法
2022-08-16 09:36:23
![](https://img.aspxhome.com/file/2023/1/68941_0s.png)
Python编程flask使用页面模版的方法
2023-08-23 19:01:55
![](https://img.aspxhome.com/file/2023/0/93960_0s.png)
利用python脚本如何简化jar操作命令
2021-02-12 11:08:15
PHP中的排序函数sort、asort、rsort、krsort、ksort区别分析
2023-11-23 11:50:55
Python中利用pyqt5制作指针钟表显示实时时间(指针时钟)
2023-04-30 22:11:13
![](https://img.aspxhome.com/file/2023/6/82746_0s.jpg)
Python中方法的缺省参数问题解读
2022-10-07 17:00:45
![](https://img.aspxhome.com/file/2023/9/92059_0s.png)
python基于celery实现异步任务周期任务定时任务
2021-06-14 05:20:26
![](https://img.aspxhome.com/file/2023/0/109350_0s.png)
javascript实现锁定网页、密码解锁效果(类似系统屏幕保护效果)
2023-08-18 20:01:36