Mailgun’s API is really nice and super-simple to use. However, I was having issues getting it to send inline images in my emails. I think the example in the documentation (here) is wrong. My files were coming through as attachement with a filename of “inline” rather than the actual filename. The actual filename was correctly coming through in the img cid tag but because the attachments had the wrong filename, they weren’t being shown.
My solution, which seems to be working, is to use MultiDict (which can be imported from werkzeug if you’re using Flask) and create the files part of the API call like this where the filename and file object are contained in a tuple:
files=MultiDict([("inline", ("test1.jpg", open("files/test1.jpg"))), ("inline", ("test2.jpg", open("files/test2.jpg")))])
Seems to work!