码迷,mamicode.com
首页 > 编程语言 > 详细

Python3.4 邮件发送(含带中文附件)

时间:2015-03-14 09:38:09      阅读:162      评论:0      收藏:0      [点我收藏+]

标签:python   email   中文附件   

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()

Python3.4 邮件发送(含带中文附件)

标签:python   email   中文附件   

原文地址:http://blog.csdn.net/u013511642/article/details/44251799

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!