zoukankan      html  css  js  c++  java
  • 发邮件,附件变成二进制文件

    发送的是带附件的邮件,发送完成后,去检查发现,附件变成二进制文件了

    出错的代码主要是这一句:

    att1["Content-Disposition"] = 'attachment; filename="test.txt"'

    只要改正这里就可以了

    问题代码

    att1 = MIMEText(open('test.txt', 'rb').read(), 'base64', 'utf-8')
    att1["Content-Type"] = 'application/octet-stream'
    att1["Content-Disposition"] = 'attachment; filename="test.txt"'
    message.attach(att1)

    改正后的代码

    att1 = MIMEText(open('txt.txt', 'rb').read(), 'base64', 'utf-8')
    att1["Content-Type"] = 'application/octet-stream'
    att1.add_header('Content-Disposition', 'attachment', filename='txt.txt')
    msg.attach(att1)
  • 相关阅读:
    php函数、php定义数组和数组遍历
    php语句
    php基础
    phpcms 标题设置
    上传头像预览
    简单的轮播样式
    ajax 小练习
    生成地图
    php注释规范
    thinkphp 实现分页
  • 原文地址:https://www.cnblogs.com/shiyixirui/p/14692151.html
Copyright © 2011-2022 走看看