How to send a mail with multiple attachments and custom file names using Mailgun (from Python)

回眸只為那壹抹淺笑 提交于 2019-12-06 03:16:29

After digging around for a while I discovered a sample showing exactly how to do this here.

I am leaving that code here for future reference as it was very useful:

def send_complex_message():
    return requests.post("https://api.mailgun.net/v2/DOMAIN/messages",
              auth=("api", "key-SECRET"),
              files={
                  "attachment[0]": ("FileName1.ext", open(FILE_PATH_1, 'rb')),
                  "attachment[1]": ("FileName2.ext", open(FILE_PATH_2, 'rb'))
              },
              data={"from": "FROM_EMAIL",
                    "to": [TO_EMAIL],
                    "subject": SUBJECT,
                    "html": HTML_CONTENT
              })
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!