这篇文章将为大家详细讲解有关使用python发送邮件给多人的方法,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。
代码:
#! /usr/bin/env python#coding=utf-
8from email.mime.text import MIMETextfrom email.header import Headerfrom smtplib import SMTP_SSL#qq邮箱smtp服务器
host_server = 'smtp.qq.com'#sender_qq为发件人的qq号码sender_qq = '7697****@qq.com'#pwd为qq邮箱的授权码
pwd = 'h**********bdc' ## h**********bdc#发件人的邮箱
sender_qq_mail = '7697****@qq.com'#收件人邮箱receivers = ['yiibai.com@gmail.com','****su@gmail.com']#邮件的正文内容mail_content = '你好,这是使用python登录qq邮箱发邮件的测试'
#邮件标题mail_title = 'Maxsu的邮件'
#ssl登录smtp = SMTP_SSL(host_server)
#set_debuglevel()是用来调试的。参数值为1表示开启调试模式,参数值为0关闭调试模式smtp.set_debuglevel(1)
smtp.ehlo(host_server)
smtp.login(sender_qq, pwd)
msg = MIMEText(mail_content, "plain", 'utf-8')
msg["Subject"] = Header(mail_title, 'utf-8')
msg["From"] = sender_qq_mail
msg["To"] = Header("接收者测试", 'utf-8') ## 接收者的别名smtp.sendmail(sender_qq_mail, receivers, msg.as_string())
smtp.quit()
关于使用python发送邮件给多人的方法就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。
原文链接:https://www.py.cn/faq/python/21560.html