• python smptl attachment filename messy code tcmime.xxx.bin email 附件名称 .bin乱码


      文件名称也要转为 bytes,使用对应编码 encode 

    或者

       from email.header import Header

    att2["Content-Disposition"] = 'attachment; filename="%s"'%
      str(Header(filename,'utf-8'))

    # encoding=utf-8
    import os
    import smtplib import mimetypes from email.mime.audio import MIMEAudio from email.mime.multipart import MIMEMultipart from email.header import Header _user = "xy@" _pwd = "y" _to = "00000@qq.com" msg_ = MIMEMultipart() msg_["Subject"] = "don't panic" msg_["From"] = "_user" msg_["To"] = "xy@dois.top" path = ur"F:media音乐Springloll - 랄라라.mp3" att2 = MIMEAudio(open(path, 'rb').read(),"mp3") att2["Content-Type"] = mimetypes.guess_type(path)[0] # or 'application/octet-stream' att2["Content-Disposition"] = 'attachment; filename="%s"'%str(Header(os.path.basename(path), 'UTF-8')) msg_.attach(att2) try: s = smtplib.SMTP_SSL("smtp.qq.com", 465) s.login(_user, _pwd) s.sendmail(_user, [_to], msg_.as_string()) s.quit() print "Success!" except smtplib.SMTPException, e: print "Falied,", e, type(e)
  • 相关阅读:
    三连击
    铺地毯
    超级玛丽游戏
    A+B problem
    怎么感觉欠缺点什么、灵光在哪,让我顿悟下
    2016年10月,人生的转折点。
    python第七天
    python第六天
    汉诺塔问题(Hanoi Tower)递归算法解析(Python实现)
    计算多数的乘积(Python实现)
  • 原文地址:https://www.cnblogs.com/willowj/p/8368235.html
Copyright © 2020-2023  润新知