(由于 Mailgun 没有 python 库,这适用于 CURL 和 Python)
我们正在使用沙盒服务器,但无法访问文件系统。
这是mailgun提供的例子:
def send_complex_message():
return requests.post(
"https://api.mailgun.net/v2/samples.mailgun.org/messages",
auth=("api", "key-3ax6xnjp29jd6fds4gc373sgvjxteol0"),
files=[("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>"})
如您所见,文件名仅隐含在 open() 调用中。
鉴于我们无法访问文件系统,我们从远程位置下载文件并传递数据。
这会在邮件中发送数据,但会忽略文件名,这使得客户端几乎不可能打开文件,因为他们必须猜测每个附件的文件扩展名。
我们如何手动指定文件名?
谢谢!