In Django, I am trying to render a dynamically generated image for a HTML email. So far, this has been working when I use base64, but this type of image cannot be displayed in Gmail (in Outlook it works fine).
Do anyone knows how to render it maybe as PNG? I was avoiding save it, sinceI don't know if it should be fine doing that on a web server. I would like to pass it as a variable to render.
Working rendering in base64
# Get map image
img_url = "https://api.mapbox.com/styles/v1/mapbox/streets-v11/static/pin-l+e7ab3c(%s,%s)/%s,%s,15/500x500?access_token=pk.xxxxxxx" % (lng,lat,lng,lat)
response = requests.get(img_url)
usr_map = ("data:" + response.headers['Content-Type'] + ";" + "base64," + str(base64.b64encode(response.content).decode("utf-8")))
context = {
...
'usr_map': usr_map,
...
}
# Add email subject
subject = "Subject"
html_content = render_to_string('main/customer_order_confirmation.html', context)
plain_message = strip_tags(html_content)
# Envio de email al cliente
send_mail(subject=subject, message=plain_message, from_email="xxx@xxx.xx",
recipient_list=[xxx@xxx.xx], html_message=html_content, fail_silently=False)
Working rendering in base64
# HTML email
...
<img alt="Logo" src="{{ usr_map }}">
...