python 发邮件
伊谢尔伦
伊谢尔伦 2017-04-18 10:24:29
0
1
717

用python 发送带zip格式的邮件,邮件发送成功了,但是附件打不开是,代码如下

import smtplib
from email import encoders
from email.mime.base import MIMEBase
from email.mime.multipart import MIMEMultipart

def send_file_zipped(the_file):

themsg = MIMEMultipart()
themsg['Subject'] = the_file
themsg['to'] = 'xxx'
themsg['from'] = 'xxx'
themsg.preamble = the_file
msg = 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 '发送成功'
except Exception, e:
    print str(e)

if name == "__main__":

file = '20170305'
send_file_zipped(file)

找了好多方法,都是这个结果,请教各位是哪里出了问题,邮件附件显示如下:

伊谢尔伦
伊谢尔伦

小伙看你根骨奇佳,潜力无限,来学PHP伐。

全員に返信(1)
刘奇

私が書いたものを試してみてください。これは Sina メール経由で送信されます。ここから、任意の添付ファイル形式で送信できます。

いいねを押す +0
人気のチュートリアル
詳細>
最新のダウンロード
詳細>
ウェブエフェクト
公式サイト
サイト素材
フロントエンドテンプレート
私たちについて 免責事項 Sitemap
PHP中国語ウェブサイト:福祉オンライン PHP トレーニング,PHP 学習者の迅速な成長を支援します!