python 3.6 群发 附件 html格式 邮件

附件发送有点问题,网易web端接收成功,qq和其他邮箱附件接收有问题,不能成功接收附件



# -*- coding:utf-8 -*-
import smtplib
import os
from email.mime.text import MIMEText  
from email.mime.multipart import MIMEMultipart  
from email import encoders

#从文本导入用户清单
test= open('D:\\python\\Project\\AtuoEmail\\Date\\differentnamelist这个是收件人名单的文本文件.txt','r',encoding="utf-8")
# print(test)
receiversname = test.readline()
test.close()
receivernamelist=receiversname.split(",")

 
  
senderuser = '[email protected]'
senderpwd = '1234qwerasdzxc'


#邮件正文相关
msg = MIMEMultipart()  
msg['Subject'] = '员工培训邮件'
mail_msg = """

微软雅黑, sans-serif;"> Dear all 微软雅黑, sans-serif;">

微软雅黑","sans-serif";color:black"> 这里是html邮件的正文,随便怎么写,哈哈哈哈或或或或或或或或或。深圳您的加入。近年来电信诈骗、网络谣言、企业泄密,等信息安全事件频繁发生,您有责任和义务保护的企业内部信息和客户信息。

微软雅黑","sans-serif";color:#080036">  

微软雅黑","sans-serif";color:#080036">  

微软雅黑","sans-serif";color:#080036">  

微软雅黑","sans-serif";color:#1F497D"> 如您有任何问题和建议欢迎随时联系我

微软雅黑","sans-serif";color:#1F497D"> """ content1 = MIMEText(mail_msg, 'html', 'utf-8')

#附件相关
msg.attach(content1)
attfile = 'D:\\python\\Project\\AtuoEmail\\2017这个是邮件附件的绝对路径.pdf'
basename = os.path.basename(attfile)
fp = open(attfile, 'rb')
att = MIMEText(fp.read(), 'base64', 'utf-8')
att["Content-Type"] = 'application/octet-stream'
att.add_header('Content-Disposition', 'attachment',filename=("gbk","", basename))
encoders.encode_base64(att)
msg.attach(att)


#发送相关
s = smtplib.SMTP('smtp.MyEmailServer.com')
s.login(senderuser,senderpwd)
s.sendmail(senderuser, receivernamelist, msg.as_string())
print('发送成功')  
s.close()

os.system('D:\\python\\Project\\AtuoEmail\\Sendlog.bat') #通过调用sendlog 记录邮件发送日志。

你可能感兴趣的:(python 3.6 群发 附件 html格式 邮件)