请考虑位于此处的 Mailgun 文档中的此示例:http ://documentation.mailgun.com/api-sending.html#examples
def send_complex_message():
return requests.post(
"https://api.mailgun.net/v2/samples.mailgun.org/messages",
auth=("api", "key-3ax6xnjp29jd6fds4gc373sgvjxteol0"),
files=MultiDict([("attachment", open("files/test.jpg")),
("attachment", open("files/test.txt"))]),
data={"from": "Excited User <me@samples.mailgun.org>",
"to": "foo@example.com",
"cc": "baz@example.com",
"bcc": "bar@example.com",
"subject": "Hello",
"text": "Testing some Mailgun awesomness!",
"html": "<html>HTML version of the body</html>"})
这对我不起作用。当电子邮件到达时,它只有一个附件。我在 python-bottle 中使用 MultiDict 对象。我只分解了文件字典,所以我可以按如下方式检查它:
files=MultiDict([("attachment", ("file1.txt", "text file 1"),
("attachment", ("file2.txt", "text file 2")])
当您执行 files.values() 时,它只有一个条目“file2.txt”。这是有道理的。如果我也尝试 append() 一个条目,我会看到相同的行为。如果“密钥”相同(在这种情况下为“附件”),它将覆盖现有记录。
如果我给它提供像附件 1 和附件 2 之类的唯一键,API 会接受该帖子,但邮件是在没有附件的情况下发送的。
所以我想我的问题是:
1) 瓶子中的 MultiDict 对象是否存在差异导致此操作失败?似乎不允许在字典中有多个条目具有相同的键?
2)我应该做一些无证的事情来向mailgun提交多个文件吗?还是不可能这样做?