0

I try to send an email with django , its working fine but i want to send a HttpReponse or somthing like that after the email sent , is that possible to keep using thread for that ?


class EmailThread(threading.Thread):
    def __init__(self, subject, html_content, recipient_list, sender,name):
        self.subject = subject
        self.recipient_list = recipient_list
        self.html_content = html_content
        self.sender = sender
        threading.Thread.__init__(self)
        self.name= name

    def run(self):
        msg = EmailMessage(self.subject, self.html_content, self.sender, self.recipient_list)
        msg.attach_file('/tmp/{username}.{filename}'.format(username=self.name,filename='proformas')+ '.pdf')
        msg.content_subtype = "html"  # Main content is now text/html
        msg.encoding = 'utf-8'
        if(msg.send()):
            print('yes')
            return HttpResponse('SENT')



def send_mail(request,pk):
    commande = get_object_or_404(Commande,id=pk)
    name  = commande.Client.Raison_social
    html_nadjib = render_to_string('Proformas/msg.html',{'raison_social':name,'Date':datetime.date.today()})
    to_emails = ['adzadadazda@outlook.com']
    subject = "azdzadaz"
    sender = 'aazdazdazadazdb@gmail.com'
    # EmailThread(subject, html_nadjib, to_emails, sender, name).start()
    if(EmailThread(subject, html_nadjib, to_emails, sender, name).start()):
     return HttpResponse('SENT')
    else:
        return HttpResponse('not sent')




itjuba
  • 518
  • 4
  • 23
  • Does this answer your question? [How to get the return value from a thread in python?](https://stackoverflow.com/questions/6893968/how-to-get-the-return-value-from-a-thread-in-python) – cetver Jun 23 '20 at 23:23
  • if you want to send a HttpReponse or somthing like that **after** the email sent, why you use thread? – minglyu Jun 24 '20 at 07:14

0 Answers0