Queening and storing EMAIL_BACKEND for django.
- Free software: GNU Affero General Public License v3
- Documentation: https://django-email-queue.readthedocs.io.
You don't have to change the way you send messages, this app will plugin into the usual django plumbing.
This way all the email send though django EMAIL_BACKEND will get stored for auditing.
You don't have to setup overhead infrastructure (e.g. celery, redis and rabbitmq) just to send emails asynchronously. You can use a simple worker that will send queued emails.
When you get big and having a MQ and all that is a good choice, all you have to to is set EMAIL_QUEUE_EMAIL_BACKEND to 'djcelery_email.backends.CeleryEmailBackend'. This way you get message storing for auditing and will use pro setup for asynchronously ran tasks.
Install Django email queue:
pip install django-email-queue
This is a plugin replacement for your current EMAIL_BACKEND. You'll still use it to send actual messages, but before them they'll get stored and queued in models visible from admin panel.
EMAIL_BACKEND = 'django_email_queue.backends.EmailBackend'
EMAIL_QUEUE_EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
INSTALLED_APPS = [
...
'django_email_queue.apps.DjangoEmailQueueConfig',
]
Now you have a few options to setup queue processing
- Run django_email_queue.worker from terminal to continuously send emails:
python -m django_email_queue.worker
Set EMAIL_QUEUE_SLEEP_TIME to number of settings to sleep between runs.
- Run django command to process queue and exit:
python manage.py send_queued_messages
- Manually from django admin for :
Does the code actually work?
$ pipenv install --dev $ pipenv shell $ tox
We recommend using pipenv but a legacy approach to creating virtualenv and installing requirements should also work. Please install requirements/development.txt to setup virtual env for testing and development.
This package was created with Cookiecutter and the wooyek/cookiecutter-django-app project template.