Send email asynchronously without celery

PHOTO EMBED

Fri Jul 01 2022 08:56:09 GMT+0000 (Coordinated Universal Time)

Saved by @mazdakdev #python #django

import threading
from django.core.mail import EmailMessage
from django.conf import settings

class EmailThread(threading.Thread):

    def __init__(self, email_message):
        self.email_message = email_message
        threading.Thread.__init__(self)

    def run(self):
        print(self.email_message.send())
        
        
        
email_message = EmailMessage(
                "subject",
                "message",
                settings.EMAIL_HOST_USER,
                ["example@mail.com"]
            )
        

EmailThread(email_message).start()
content_copyCOPY