V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
nightstart
V2EX  ›  问与答

Python 发邮件遇到邮件客户端附件名显示不对的问题

  •  
  •   nightstart · 2018-10-27 22:13:49 +08:00 · 1679 次点击
    这是一个创建于 2000 天前的主题,其中的信息可能已经有所发展或是发生改变。

    message['Subject'] = Header(subject, 'utf-8') message.attach(MIMEText(contents, 'plain', 'utf-8'))

    if filename is not None and path is not None:
        attach_file = MIMEText(open(path, 'rb').read(), 'base64', 'utf-8')
        attach_file["Content-Type"] = 'application/octet-stream'
        attach_file.add_header('Content-Disposition', 'attachment', filename=('gb2312', '', filename))
        message.attach(attach_file)
    try:
        result = True
        errors = ''
        if int(usessl):
            smtpObj = smtplib.SMTP_SSL(mail_host, port)
        else:
            smtpObj = smtplib.SMTP(mail_host, port)
        smtpObj.login(mail_user, mail_pass)
        smtpObj.sendmail(sender, receivers, message.as_string())
    

    这是我邮件主要的代码、目前用各个邮箱的网页端接收邮件和附件都是正常的。但是用 windows 端的 outlook 客户端接收邮件的时候就会出现问题 附件的名称会被改成 Attachment_1.txt 而不是原来的名称和后缀 跟各位大佬请教一下 这个是要在哪里加什么东西吗 = = 我被困扰好久了

    Python3 MacOS 和 Linux7 环境下

    nightstart
        1
    nightstart  
    OP
       2018-10-27 22:26:02 +08:00
    上浮
    nightstart
        2
    nightstart  
    OP
       2018-10-28 19:33:20 +08:00
    上浮 1
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2875 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 15:20 · PVG 23:20 · LAX 08:20 · JFK 11:20
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.