python 發(fā)郵件
問(wèn)題描述
用python 發(fā)送帶zip格式的郵件,郵件發(fā)送成功了,但是附件打不開(kāi)是,代碼如下
import smtplibfrom email import encodersfrom email.mime.base import MIMEBasefrom email.mime.multipart import MIMEMultipart
def send_file_zipped(the_file):
themsg = MIMEMultipart()themsg[’Subject’] = the_filethemsg[’to’] = ’xxx’themsg[’from’] = ’xxx’themsg.preamble = the_filemsg = MIMEBase(’application’, ’zip’)zf = open(the_file + ’.zip’, ’rb’)msg.set_payload(zf.read())encoders.encode_base64(msg)msg.add_header(’Content-Disposition’, ’attachment’, filename=the_file + ’.zip’)themsg.attach(msg)themsg = themsg.as_string()try: server = smtplib.SMTP() server.timeout = 30 server.connect(’smtp.exmail.qq.com’) server.login(’xxx’, ’xxx’) server.sendmail(’xxx’, ’xxx’, themsg) server.quit() print ’發(fā)送成功’except Exception, e: print str(e)
if name == '__main__':
file = ’20170305’send_file_zipped(file)
找了好多方法,都是這個(gè)結(jié)果,請(qǐng)教各位是哪里出了問(wèn)題,郵件附件顯示如下:
問(wèn)題解答
回答1:你可以試一下我寫的這個(gè),用的是新浪郵箱發(fā)的,在我這兒是無(wú)論什么附件格式都可以發(fā)
相關(guān)文章:
1. angular.js - 輸入郵箱地址之后, 如何使其自動(dòng)在末尾添加分號(hào)?2. javascript - 后臺(tái)管理系統(tǒng)左側(cè)折疊導(dǎo)航欄數(shù)據(jù)較多,怎么樣直接通過(guò)搜索去定位到具體某一個(gè)菜單項(xiàng)位置,并展開(kāi)當(dāng)前菜單3. 如何解決docker宿主機(jī)無(wú)法訪問(wèn)容器中的服務(wù)?4. javascript - Web微信聊天輸入框解決方案5. javascript - 如何使用nodejs 將.html 文件轉(zhuǎn)化成canvas6. python - Scrapy存在內(nèi)存泄漏的問(wèn)題。7. 如何用筆記本上的apache做微信開(kāi)發(fā)的服務(wù)器8. CSS3 畫如下圖形9. angular.js - $stateChangeSuccess事件在狀態(tài)跳轉(zhuǎn)的時(shí)候不執(zhí)行?10. android - rxjava merge 返回Object對(duì)象數(shù)據(jù)如何緩存
