python 發(fā)郵件
問題描述
用python 發(fā)送帶zip格式的郵件,郵件發(fā)送成功了,但是附件打不開是,代碼如下
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)
找了好多方法,都是這個結(jié)果,請教各位是哪里出了問題,郵件附件顯示如下:
問題解答
回答1:你可以試一下我寫的這個,用的是新浪郵箱發(fā)的,在我這兒是無論什么附件格式都可以發(fā)
相關(guān)文章:
1. 微信公眾號在線生成二維碼帶參數(shù)怎么搞?2. 微信開放平臺 - android 微信支付后點完成按鈕,后回調(diào)打開第三方頁面,屏幕閃動,求解決方法3. PHP單例模式4. javascript - 這種效果是輪播的效果嗎??沒有思路,求解釋。謝謝大家5. css - font-face引入的新字體無法在火狐瀏覽器上顯示?但是谷歌可以?6. css3 - 誰有時間能給翻譯一下,應(yīng)該都是CCS的樣式屬性的中文名稱,或者有什么網(wǎng)站有CSS屬性的中英對照表也行。7. html5 - html web 打包成android app8. node.js - 利用vue-cli 構(gòu)建執(zhí)行到npm run dev 報錯,求解~9. javascript - 微信小程序的分享問題10. css3 - 能否在CSS中定義“對特定字體的文本加粗”?
