Created
July 3, 2012 21:39
-
-
Save fission6/3043478 to your computer and use it in GitHub Desktop.
Send email with text and html in django
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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