Skip to main content

An email manager for sending emails with templates, mail history and admin.

Project description

https://badge.fury.io/py/django-saas-email.svg https://travis-ci.org/unicorn-supplies/django-saas-email.svg?branch=master https://codecov.io/gh/unicorn-supplies/django-saas-email/branch/master/graph/badge.svg

An email manager for sending emails with templates, mail history and admin.

Features

Documentation

The full documentation is at https://django-saas-email.readthedocs.io.

Quickstart

Installation

Installation with pip:

pip install django-saas-email

Add it to your INSTALLED_APPS:

INSTALLED_APPS = (
    ...
    'django_saas_email.apps.DjangoSaasEmailConfig',
    ...
)

Add a template engine TEMPLATES:

TEMPLATES = [
    ...
    {
        "BACKEND": "django.template.backends.django.DjangoTemplates",
        "APP_DIRS": True,
        "DIRS": ["django_saas_email/templates/"],
        "NAME": "email",
        "OPTIONS": {"string_if_invalid": "{%s}"},
    }
]

JSONField

We are using the Postgres JSONField as default. If you installed psycopg2, everything should work fine.

If you are using a different database, you also need to install jsonfield:

pip install jsonfield

Adding the Sendgrid API Key to your settings

In settings.py:

SENDGRID_API_KEY=<....>

Other optional settings:

DJANGO_SAAS_TEST_EMAIL_ADDRESS=youremailfortesting@example.org
DJANGO_SAAS_FOOTER="""Follow <a href="#" style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 12px; color: #999; text-decoration: underline; margin: 0;">@yourcompany</a> on Twitter"""

Sending emails

from django_saas_email.utils import create_and_send_mail

context={
  'first_name': 'John',
  'last_name': 'Doe',
}

create_and_send_mail(
  template_name="hello_world",
  context=context,
  to_address="john.doe@example.org"
)

This will create an email and send it with Sengrid.

You should use http://premailer.dialect.ca or django-premailer to create Inline CSS in HTML

Background sending

This module sends emails asynchronously. To do that, it uses celery. You will need to run and configure celery to really send emails using the library.

The best source to do that is First Steps with Celery.

But you may use the following simple guide if you want to make it fast:

  1. Create a celery.py file aside your wsgi.py file with the following content:

from __future__ import absolute_import, unicode_literals
import os
from celery import Celery

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings')

app = Celery(<YOUR_APP_NAME>)
app.config_from_object('django.conf:settings', namespace='CELERY')
app.autodiscover_tasks()

Change <YOUR_APP_NAME> to the name of your app.

  1. Install RabbitMQ.

  2. Run celery:

celery -A <YOUR_APP_NAME> worker -B -l debug

Change <YOUR_APP_NAME> to the name of your app.

  1. Now you might just send the email with no problem using create_and_send_mail function.

Running Tests

Does the code actually work?:

source <YOURVIRTUALENV>/bin/activate
(myenv) $ pip install tox
(myenv) $ tox

History

0.1.0 (2017-07-24)

  • First release on PyPI.

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-saas-email-0.1.23.tar.gz (16.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_saas_email-0.1.23-py2.py3-none-any.whl (23.0 kB view details)

Uploaded Python 2Python 3

File details

Details for the file django-saas-email-0.1.23.tar.gz.

File metadata

  • Download URL: django-saas-email-0.1.23.tar.gz
  • Upload date:
  • Size: 16.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.0 setuptools/39.1.0 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.6

File hashes

Hashes for django-saas-email-0.1.23.tar.gz
Algorithm Hash digest
SHA256 55f76156d61e8c184b0499d3fdde3e38685ee03b45c1edfa401bb5bb28fc0c0a
MD5 aaee7ff833a54a40a8c1ec15dd469c05
BLAKE2b-256 0c7022220310c36227b0f96714e1c39ba8ecb325dd24251c20a4154de48165cd

See more details on using hashes here.

File details

Details for the file django_saas_email-0.1.23-py2.py3-none-any.whl.

File metadata

  • Download URL: django_saas_email-0.1.23-py2.py3-none-any.whl
  • Upload date:
  • Size: 23.0 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.0 setuptools/39.1.0 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.6

File hashes

Hashes for django_saas_email-0.1.23-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 72d3a79e8e89a92a99c5d00df6e5dcb0b39e1fc3968b0cf419e5198c721e5df8
MD5 5f9fbba7c5e55c8335f02bd63533b90e
BLAKE2b-256 58c836edec2657180ada3835333c78ea496057ec74c290e41a540facc765c263

See more details on using hashes here.

Supported by

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