Skip to main content

Django Email Automation

Project description

https://img.shields.io/pypi/v/django_solar https://img.shields.io/pypi/pyversions/django_solar

Django email automation with cron.

Tested with :

  • django==3.1.1

Setup

Install with pip :

pip install django_solar

Add django_solar to django apps installed :

INSTALLED_APPS = [
    ...
    'django_solar',
]

Set Django email backend :

# Take a look at https://github.com/anymail/django-anymail

ANYMAIL = {
    "MAILJET_API_KEY": env.str('MAILJET_API_KEY'),
    "MAILJET_SECRET_KEY": env.str('MAILJET_SECRET_KEY'),
}
MAILJET_API_KEY = env.str('MAILJET_API_KEY')
MAILJET_SECRET_KEY = env.str('MAILJET_SECRET_KEY')

EMAIL_BACKEND = "anymail.backends.mailjet.EmailBackend"
DEFAULT_FROM_EMAIL = "hello@snoweb.fr"
SERVER_EMAIL = "hello@snoweb.fr"

Set django_solar context :

DS_CRON_HOUR = 1  # Period of cron in hours
DS_EVENT_MANAGER = "tests.manager.EventManager"  #  Class manager of events

Set cron command

0 * * * * python manage.py solar

Defines Events

Example of EventManger :

from django_solar import AEventManager, MailTemplate
from django_solar.models import Mail
from datetime import datetime


class EventManager(AEventManager):

    def event_something(self):
        Mail.objects.create(
            mail='test@exemple.com',  #  Receiver
            send_at=datetime.now(),  #  Datetime send
            html=MailTemplate.get(key='test'),  #  HTML of email
            subject="Test Django Solar"  #  Subject of email
        )

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django_solar-0.0.3.tar.gz (17.4 kB view hashes)

Uploaded Source

Built Distribution

django_solar-0.0.3-py3-none-any.whl (19.9 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page