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. angular.js - angular做點(diǎn)擊購買時的遮罩層2. android - NavigationView 的側(cè)滑菜單中如何保存新增項(通過程序添加)3. 冒昧問一下,我這php代碼哪里出錯了???4. http://run.php.cn/在線PHP程序運(yùn)行結(jié)果不正確5. tp5 不同控制器中的變量調(diào)用問題6. 關(guān)于thinkphp 5.1中,ajax提交數(shù)據(jù)url的格式寫法,加花括號就出錯,請老師指點(diǎn)7. 模型的優(yōu)點(diǎn)8. 老師 我是一個沒有學(xué)過php語言的準(zhǔn)畢業(yè)生 我希望您能幫我一下9. 提示語法錯誤語法錯誤: unexpected ’abstract’ (T_ABSTRACT)10. Thinkphp5.1報錯不支持Redis
