计算机管理系统:电脑网络技术记录本

Python

当前位置:首页 > 程序语言集合 > Python

python 利用smtplib模块进行html内容邮件群发

# coding:utf8
import smtplib
from email.mime.multipart import MIMEMultipart
from email.header import Header
from email.mime.text import MIMEText

con = smtplib.SMTP_SSL('smtp.163.com',465)  # 连接邮箱服务器
con.login('123456@163.com','邮箱登陆授权码')   # 登陆邮箱账号

msg = MIMEMultipart()       # 准备数据

sub = Header('邮件内容标题','utf8').encode()  # 填写邮件标题和编码
msg['Subject'] = sub

msg['From'] = '123456@163.com <123456@163.com>'  # 设置邮件头部发件人信息

msg['To'] = 'xxxx@163.com;xxxx@qq.com'   # 设置设置一个头部收件人信息

htmltext = """ 
<h3>我是一个3号大小字体的邮件正文标题标题</h3>
<p>我是邮件内容,在html里面一对p标签就是一段内容。</p>
<p>比如说现在这段文字,就是用的第2对p标签,所以我是在第2段。</p>
<a href="http://www.heisiwu.com" target="_blank">点击我可以跳转到黑丝屋图片网站</a>
<img src="http://www.heisiwu.com/wp-content/uploads/2022/04/b221380c2763982.jpg" />
"""       # 编辑html内容。

html = MIMEText(htmltext,'html','utf8')  # 这边把邮件类型改为html,发送文本内容就改为plain。

# python的smtplib邮件发送的文本类型,和html类型的区别就在于上面两段了,文本类型邮件教程在:
#   http://www.diannaoblog.com/python/145.html

msg.attach(html)  # 把邮件头部和邮件内容关联在一起

to2 = ['xxxx@163.com','xxxx@qq.com'] # 设置一个收件人群发列表变量
con.sendmail('123456@163.com',to2,msg.as_string())   #  设置发件人账号和收件人账号
con.quit()       # 断开邮箱服务器连接,退出邮件服务器。

python 利用smtplib模块进行html内容邮件群发

文章评论

表情

共 0 条评论,查看全部
  • 这篇文章还没有收到评论,赶紧来抢沙发吧~