I am using Django's EmailMessage class for sending auto mail, from a view. However the website literally stops showing the next render page (which is on a modal), until the Email has been sent. If I remove Email sending stuff then the website is very fast and works properly. Please guide as to how to send mail also while not forcing the user to wait for the mail sending process. My partial view codes are below for reference:
email =EmailMessage(
'Message received',
'You received a message....',
settings.DEFAULT_FROM_EMAIL,
[request.user.email],
reply_to=['noreply@example.com'])
email.content_subtype = "html"
email.send(fail_silently=True)
return JsonResponse({"instance": rendered,"valid":True}, status=200)
Edit: Update:
I have also tried the async_to_sync function to call the email.send method as suggested in the docs. However the main flow still waits for the mail sending process.