I'm having problems with how I can send multiple inline messages using Apache Mailgun from a Python application using a query library. I currently have (using jinja2 for templates and flasks as web graphics hosted on Heroku):
def EmailFunction(UserEmail):
Sender = 'testing@test.co.uk'
Subject = 'Hello World'
Text = ''
name = re.sub('@.*','',UserEmail)
html = render_template('GenericEmail.html', name=name)
images = []
imageloc = os.path.join(dirname, 'static')
images.append(open(os.path.join(imageloc,'img1.jpg')))
images.append(open(os.path.join(imageloc,'img2.jpg')))
send_mail(UserEmail,Sender,Subject,Text,html,images)
return html
def send_mail(to_address, from_address, subject, plaintext, html, images):
r = requests.\
post("https://api.mailgun.net/v2/%s/messages" % app.config['MAILGUN_DOMAIN'],
auth=("api", app.config['MAILGUN_KEY']),
data={
"from": from_address,
"to": to_address,
"subject": subject,
"text": plaintext,
"html": html,
"inline": images
}
)
return r
Thus, the letter is sent normally, but at the end of the letter there are no images. When I click to download them, they are not displayed. Images are specified in HTML according to the api mailgun (simplified, of course!);
<img src="cid:img1.jpg"/>
<img src="cid:img2.jpg"/>
etc ...
Obviously, I am doing something wrong, however, I tried to link them using the request.files object, which did not even send an email and did not give any errors, so I assume that this is the wrong option.
, .
, HTML ? , ( , ).