我是靠谱客的博主 跳跃微笑,这篇文章主要介绍python发送html格式邮件,python3发送html格式的邮件,现在分享给大家,希望可以做个参考。

def send_mail(to_list, sub, content, attpath):

me = "*******" + ""

msg = MIMEMultipart()

msg['Subject'] = sub

msg['From'] = me

msg['To'] = ";".join(to_list)

htmlf=open(attpath,'r',encoding="utf-8")

htmlcont=htmlf.read()

email_text = MIMEText(htmlcont, _subtype='html')

msg.attach(email_text)

sep = os.sep

attname = attpath.split(sep)[-]

# 首先是xlsx类型的附件

email_att = MIMEApplication(open(attpath, 'rb').read())

email_att.add_header('Content-Disposition', 'attachment', filename=attname)

msg.attach(email_att)

try:

server = smtplib.SMTP()

server.connect(mail_host) # 连接服务器

server.login(mail_user, mail_pass) # 登录操作

server.sendmai

最后

以上就是跳跃微笑最近收集整理的关于python发送html格式邮件,python3发送html格式的邮件的全部内容,更多相关python发送html格式邮件,python3发送html格式内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(141)

评论列表共有 0 条评论

立即
投稿
返回
顶部