Skip to content

Instantly share code, notes, and snippets.

@olivx
Created March 27, 2018 21:38
Show Gist options
  • Save olivx/54a15611d38306eb8db9a6b2b1757b27 to your computer and use it in GitHub Desktop.
Save olivx/54a15611d38306eb8db9a6b2b1757b27 to your computer and use it in GitHub Desktop.
from django.core.mail import get_connection, EmailMultiAlternatives
from django.template.loader import render_to_string
connection = get_connection()
connection.open()
context = {'object': object }
html_string = render_to_string('template.html',context=context, request=request)
from_email = settings.SERVER_EMAIL
msg = EmailMultiAlternatives(
subject, html_content, from_email, email_to)
# reder html on e-mail body
msg.attach_alternative(html_content, "text/html")
# if file not existS on server, BOMMMMM!!!
msg.attach(cand_cv.resume.name, cand_cv.resume.read())
msg.send()
connection.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment