diff options
author | Evgeny Fadeev <evgeny.fadeev@gmail.com> | 2010-03-14 18:27:57 -0400 |
---|---|---|
committer | Evgeny Fadeev <evgeny.fadeev@gmail.com> | 2010-03-14 18:27:57 -0400 |
commit | 10c98242325230d2314c2f1292e75650acd8d50e (patch) | |
tree | b977974539f794324a4bb36655ae6e35ecc769a3 /forum/utils/email.py | |
parent | 7d4e81c2e6553ee9aa087d95fdc6c87f75b021df (diff) | |
parent | c2255c60fa5bca3f49fa30aa81a20fcdaa603dc3 (diff) | |
download | askbot-10c98242325230d2314c2f1292e75650acd8d50e.tar.gz askbot-10c98242325230d2314c2f1292e75650acd8d50e.tar.bz2 askbot-10c98242325230d2314c2f1292e75650acd8d50e.zip |
merged with master branch
Diffstat (limited to 'forum/utils/email.py')
-rwxr-xr-x | forum/utils/email.py | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/forum/utils/email.py b/forum/utils/email.py new file mode 100755 index 00000000..dc712572 --- /dev/null +++ b/forum/utils/email.py @@ -0,0 +1,21 @@ +from django.core.mail import send_mail, EmailMultiAlternatives +from django.conf import settings +from django.template import loader, Context +from django.utils.html import strip_tags +from threading import Thread + +def send_email(subject, recipients, template, context={}, sender=settings.DEFAULT_FROM_EMAIL, txt_template=None): + context['settings'] = settings + html_body = loader.get_template(template).render(Context(context)) + + if txt_template is None: + txt_body = strip_tags(html_body) + else: + txt_body = loader.get_template(txt_template).render(Context(context)) + + msg = EmailMultiAlternatives(subject, txt_body, sender, recipients) + msg.attach_alternative(html_body, "text/html") + + thread = Thread(target=EmailMultiAlternatives.send, args=[msg]) + thread.setDaemon(True) + thread.start() |