Created
October 2, 2012 03:46
-
-
Save renyi/3816042 to your computer and use it in GitHub Desktop.
Django sendmail (1337 template)
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
| from django.core.mail import EmailMultiAlternatives | |
| from django.utils.html import strip_tags | |
| from mezzanine.conf import settings | |
| subject, from_email, to, bcc = email_subject, settings.DEFAULT_FROM_EMAIL, user_email, manager_email | |
| text_content = strip_tags(email_template) | |
| html_content = email_template | |
| msg = EmailMultiAlternatives(subject, text_content, from_email, [to], bcc) | |
| msg.attach_alternative(html_content, "text/html") | |
| msg.send() |
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
| from django.utils.encoding import force_unicode | |
| def sendmail(subject, message, from_email, recipient_list, html_message=None): | |
| subject = force_unicode(subject) | |
| message = force_unicode(message) | |
| # from mailer import send_mail, send_html_mail | |
| # if html_message: | |
| # send_html_mail(subject, message, html_message, settings.DEFAULT_FROM_EMAIL, recipient_list) | |
| # else: | |
| # send_mail(subject, message, settings.DEFAULT_FROM_EMAIL, recipient_list) | |
| from django.core.mail import EmailMultiAlternatives | |
| email = EmailMultiAlternatives(subject, message, from_email, recipient_list) | |
| if html_message: | |
| html_message = force_unicode(html_message) | |
| email.attach_alternative(html_message, "text/html") | |
| email.send() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment