Login

django asynchronous send mail

Author:
gchandrasa
Posted:
April 11, 2010
Language:
Python
Version:
1.1
Tags:
django-asynchronous-send-mail
Score:
2 (after 2 ratings)

snippet to create asynchronous send mail in django

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
from django.core.mail import send_mail as core_send_mail
from django.core.mail import EmailMultiAlternatives
import threading

class EmailThread(threading.Thread):
    def __init__(self, subject, body, from_email, recipient_list, fail_silently, html):
        self.subject = subject
        self.body = body
        self.recipient_list = recipient_list
        self.from_email = from_email
        self.fail_silently = fail_silently
        self.html = html
        threading.Thread.__init__(self)

    def run (self):
        msg = EmailMultiAlternatives(self.subject, self.body, self.from_email, self.recipient_list)
        if self.html:
            msg.attach_alternative(self.html, "text/html")
        msg.send(self.fail_silently)

def send_mail(subject, body, from_email, recipient_list, fail_silently=False, html=None, *args, **kwargs):
    EmailThread(subject, body, from_email, recipient_list, fail_silently, html).start()

More like this

  1. Email queue in DB by fish2000 4 years, 10 months ago
  2. Better debugging mail server by yourcelf 4 years ago
  3. Using Templates to Send E-Mails by rpoulton 8 years ago
  4. Deferrable function cache decorator by bradbeattie 3 weeks, 2 days ago
  5. Send templated email with text | html | optional files by grillermo 3 years, 5 months ago

Comments

Please login first before commenting.