【问题标题】:Mailgun Attachment not attachingMailgun 附件未附加
【发布时间】:2023-03-21 02:51:02
【问题描述】:

我遇到了一个问题,我的附件没有随电子邮件一起发送(人们只会收到一封带有指定消息但没有附件的电子邮件)。我没有收到任何运行时错误,因此这似乎是服务器错误。有什么想法吗?

代码如下:

return requests.post(
    sender_info['MAIL_URL'],
    auth=('api', sender_info['MG_API']),
    files=[(
        ("attachment", attachment), 
        ("attachment", open("./Expense Transfer Form.pdf")),
    )],
    data={
        'from': sender_info['SENDER'],
        'to': recipient,
        'cc': ccemail,
        'subject': subject,
        'text': message,
        'attachment': "./Expense Transfer Form.pdf",
    }
)

【问题讨论】:

    标签: python mailgun


    【解决方案1】:

    您的文件部分格式错误,它应该是一个包含多个元组的列表

    files = [("attachment", ('attachement1',attachment,'text/pdf')),
    ("attachment, ('expense Transfer Form', open('Expense Transfer Form.pdf', 'rb'),'text/pdf'))]
    

    元组在哪里 (form_fieldname, file_info)

    您可以在 python 文档here 上查看 multipart/form-data。 请求对象没有发现您的文件是 mailgun 附件中所需的多部分文件

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-06-12
      • 2021-06-02
      • 2012-12-23
      • 2019-03-14
      • 1970-01-01
      • 1970-01-01
      • 2017-09-13
      相关资源
      最近更新 更多