当前位置: 移动技术网 > IT编程>脚本编程>Python > python 3.6 群发 附件 html格式 邮件

python 3.6 群发 附件 html格式 邮件

2018年03月29日  | 移动技术网IT编程  | 我要评论

测网速的网站,红颜知己,北京崇文门同仁堂

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 = 'wulalal@emali.com'
senderpwd = '1234qwerasdzxc'
#邮件正文相关
msg = MIMEMultipart()  
msg['Subject'] = '员工培训邮件'
mail_msg = """

Dear all

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

如您有任何问题和建议欢迎随时联系我

""" 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 记录邮件发送日志。

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网