Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to send asynchronous email using django

Tags:

This is my code:

class EmailThread(threading.Thread):     def __init__(self, subject, html_content, recipient_list):         self.subject = subject         self.recipient_list = recipient_list         self.html_content = html_content         threading.Thread.__init__(self)      def run (self):         msg = EmailMultiAlternatives(self.subject, self.html_content, EMAIL_HOST_USER, self.recipient_list)         #if self.html_content:         msg.attach_alternative(True, "text/html")         msg.send()  def send_mail(subject, html_content, recipient_list):     EmailThread(subject, html_content, recipient_list).start() 

It doesn't send email. What can I do?

like image 281
zjm1126 Avatar asked Dec 15 '10 05:12

zjm1126


People also ask

Does Django support asynchronous?

Django has support for writing asynchronous (“async”) views, along with an entirely async-enabled request stack if you are running under ASGI. Async views will still work under WSGI, but with performance penalties, and without the ability to have efficient long-running requests.

How do I send an email to multiple recipients in Django?

How to send multiple mass emails django. We need to create a Tuple of messages and send them using send mass mail. In this tutorial, we create a project which sends email using Django. We fill the data in the form and send it using Django Email.


2 Answers

it is ok now ;

import threading from threading import Thread  class EmailThread(threading.Thread):     def __init__(self, subject, html_content, recipient_list):         self.subject = subject         self.recipient_list = recipient_list         self.html_content = html_content         threading.Thread.__init__(self)      def run (self):         msg = EmailMessage(self.subject, self.html_content, EMAIL_HOST_USER, self.recipient_list)         msg.content_subtype = "html"         msg.send()  def send_html_mail(subject, html_content, recipient_list):     EmailThread(subject, html_content, recipient_list).start() 
like image 112
zjm1126 Avatar answered Oct 14 '22 21:10

zjm1126


In the long run, it may prove to be a good decision to use a third-party Django application, such as django-mailer, to handle all sorts of asynchronous email sending/management requirements.

like image 29
ayaz Avatar answered Oct 14 '22 22:10

ayaz