I'm looking to speed up loading time for my website by sending my mail asynchronously. Currently, my code looks something like this:
def myFunction(content):
result = modify(content)
send_mail('My Subject', result, 'me@example.com')
return render(request, 'page.html', result)
Using Django-Mailer, I've figured out that I can cut loading time by writing the email to the database instead of sending it immediately, then having cron + Django mailer work through the emails in my database asynchronously.
However, I like to keep my database as free from potentially sensitive information as possible, and would like to avoid writing any of the emails sent through my app to my database. Even if the data is just being written for a short time, with automatic backups there's a possibility something might be saved.
I understand if there's no solution here, but is there a way to send emails asynchronously without every writing them to a database? I really don't think this is possible, but my ideal hope would be if there was a way to return the response, and then send the email.
def myFunction(content):
result = modify(content)
return render(request, 'page.html', result)
send_mail('My Subject', result, 'me@example.com')
Django-After-Response seems to do this, but hasn't been updated since 2015.
This answer and this answer also provide potential solutions.