I am having trouble working out how I can send multiple inline messages using the Mailgun api, from a Python app using the requests library. Currently I have (using jinja2 f
As of 2020, actual documentation here: https://documentation.mailgun.com/en/latest/api-sending.html#examples
My example:
response = requests.post(
'https://api.mailgun.net/v3/' + YOUR_MAILGUN_DOMAIN_NAME + '/messages',
auth=('api', YOUR_MAILGUN_API_KEY),
files=[
('inline[0]', ('test1.png', open('path/filename1.png', mode='rb').read())),
('inline[1]', ('test2.png', open('path/filename2.png', mode='rb').read()))
],
data={
'from': 'YOUR_NAME <' + 'mailgun@' + YOUR_MAILGUN_DOMAIN_NAME + '>',
'to': [adresat],
'bcc': [bcc_adresat],
'subject': 'email subject',
'text': 'email simple text',
'html': '''<html><body>
<img src="cid:test1.png">
<img src="cid:test2.png">
</body></html>'''
},
timeout=5 # sec
)
Sending Inline Images is documented here.
In the HTML, you'll reference the image like this:
<html>Inline image here: <img src="cid:test.jpg"></html>
Then, define a Multidict, to post the files to the API:
files=MultiDict([("inline", open("files/test.jpg"))])
Disclosure, I work for Mailgun. :)