Python3.4 邮件发送(含带中文附件)
2018-07-20 来源:open-open
import smtplib import os from email.mime.text import MIMEText from email.mime.multipart import MIMEMultipart from email import encoders user = '*******@qq.com' pwd = '*******' to = ['******@139.com', '******@qq.com'] msg = MIMEMultipart() msg['Subject'] = '这里是主题...' content1 = MIMEText('这里是正文!', 'plain', 'utf-8') msg.attach(content1) attfile = 'C:\\Users\\hengli\\Pictures\\CameraMan\\哈哈.doc' 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.qq.com') s.login(user, pwd) s.sendmail(user, to, msg.as_string()) print('发送成功') s.close()
标签: isp
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点!
本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。
最新资讯
热门推荐