【问题标题】:Sending attachments in Mandrill在 Mandrill 中发送附件
【发布时间】:2014-09-08 22:04:07
【问题描述】:

我正在尝试使用 Mandrill 发送附件。我已将此添加到我的对象中:

    "attachments": [
      {
        "type": "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
        "name": "filename-removed.docx"
        "content": attachment
      }
    ]

附件是我上传文件到这个base64转换器时得到的一个大字符串:

http://www.motobit.com/util/base64-decoder-encoder.asp

我收到此错误:

Uncaught SyntaxError: Unexpected string 

我尝试将字符串粘贴到那里,并使其成为变量(如上),但我不断收到此错误。有没有更简单的方法来做到这一点?我做错了什么?

【问题讨论】:

    标签: email base64 email-attachments mandrill


    【解决方案1】:

    尝试直接操作文件并将其编码为base64,而不是粘贴字符串。在 Python 中:

    import base64
    
    file = open(path/to/file.docx)
    encoded = base64.b64encode(file.read())
    file.close()
    

    然后将您的附件设置为encoded,您应该一切顺利。

    或者,您可能只需要在"filename-removed.docx" 后面加一个逗号。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-10-14
      • 2015-07-11
      • 2014-07-26
      • 2015-10-22
      • 2013-02-15
      • 2014-11-16
      • 1970-01-01
      • 2016-08-07
      相关资源
      最近更新 更多