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)
找了好多方法,都是這個(gè)結(jié)果,請(qǐng)教各位是哪里出了問題,郵件附件顯示如下:

問題解答
回答1:你可以試一下我寫的這個(gè),用的是新浪郵箱發(fā)的,在我這兒是無論什么附件格式都可以發(fā)
相關(guān)文章:
1. boot2docker無法啟動(dòng)2. docker-compose中volumes的問題3. node.js - antdesign怎么集合react-redux對(duì)input控件進(jìn)行初始化賦值4. docker安裝后出現(xiàn)Cannot connect to the Docker daemon.5. 關(guān)于docker下的nginx壓力測(cè)試6. java - SSH框架中寫分頁時(shí)service層中不能注入分頁類7. dockerfile - 為什么docker容器啟動(dòng)不了?8. 關(guān)docker hub上有些鏡像的tag被標(biāo)記““This image has vulnerabilities””9. 老師,按tab鍵不起作用怎么回事10. mac里的docker如何命令行開啟呢?

網(wǎng)公網(wǎng)安備