I want to mimic the functionality that Gmail has, where you can choose to send an email at a certain time (maybe 3:34 am tomorrow) in Django.
I looked at something like django-crontab (https://pypi.org/project/django-crontab/).
I came up with an idea to use django-crontab to achieve this:
- Make a crontab that runs every minute
- Every minute, check if there are any emails that need to be sent
- Send out those emails
This feels a bit hacky and over-engineered. Is there a better way? Thanks!
You can check out celery and how to integrate it with django. Once done, task scheduling is easy,first add your gmail configuration in settings.py as follows:
Then in your tasks.py you can add the function for scheduling emails as follows:
Then finally your email template 'schedule_mail.html'
And the command to run celery service as beat:
replace 'yourapp' with name of your app. Cheers!!