Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
django html message vs emails
import os
from django.core.mail import EmailMultiAlternatives
from django.template.loader import render_to_string
from email.MIMEImage import MIMEImage
from email.utils import formataddr
ctx = {"project_name": "user/project1", "build_id": 121}
html_content = render_to_string('templates/body.html', ctx)
text_content = render_to_string('templates/body.txt', ctx)
msg = EmailMultiAlternatives(subject, text_content, formataddr("CI", ""), ['somebody@mycompany.comm'])
msg.mixed_subtype = 'related'
msg.attach_alternative(html_content, "text/html")
for fn in ['icon.png', ]:
with open(fn, 'rb') as fp:
msg_img = MIMEImage(
msg_img.add_header('Content-ID', '<{}>'.format(f))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.