Skip to content

Instantly share code, notes, and snippets.

@fission6
Created July 3, 2012 21:39
Show Gist options
  • Select an option

  • Save fission6/3043478 to your computer and use it in GitHub Desktop.

Select an option

Save fission6/3043478 to your computer and use it in GitHub Desktop.
Send email with text and html in django
def email_user(user, email, template):
"""
"""
if 'domain' not in email:
email['domain'] = SITE_DOMAIN
c = Context({'user': user, 'email' : email})
html_content = template.render(c)
text_content = strip_tags(html_content)
print 'Sending Email to {0}'.format(user)
try:
msg = EmailMultiAlternatives(
email['subject'],
text_content,
email['from'],
[user.email],
)
msg.attach_alternative(html_content, "text/html")
msg.send()
except Exception,e:
print e
print "Error for user {0}".format(user)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment