Skip to main content

templated-emails

This app abstracts the sending of emails in a way so that it is possible to switch from plain text emails to html emails, even if you are using third party apps. It does this by using a very similar mechanism as django-notifications.

Each email gets a folder. In this folder one can put:

  • short.txt (for the subject)

  • email.txt (for the plain text email)

  • email.html (optional, if an HTML email should also be sent)

A good practice is to put all emails in an emails/ folder within your templates folder, so it is easy to see what emails are being sent by your system.

Recipients can either be an array of emails (as strings) or users. If you pass users it will also try to find the users stored language (accounts.Account.language in pinax) and send it using it.

Sending an emails works like this:

from templated_emails.utils import send_templated_email
send_templated_email(["philipp@gidsy.com"], "emails/invite_friends", {"my_variable":"blafoo"})

or

user = User.objects.get(pk=1)
# this will try to switch to the correct language of the user
send_templated_email([user], "emails/invite_friends", {"my_variable":"blafoo"})

The system will add current_site (the Site object of the Django Project) and STATIC_URL (for linking in static content) to the context of your templates.

Language

Similar to django-notification the system will try to look for the language the user has set in his Account (but can be configured to other Models using settings.NOTIFICATION_LANGUAGE_MODULE) to server the right language to each user.

Inline CSS Rules

Inline CSS Rules are annoying and tedious, but a neccessity if you want to support all email clients. Since 0.3 pynliner is included that will take the CSS from the HEAD and put it into each element that matches the rule

There is a toggle you can set in settings.py to turn this feature on or off: TEMPLATEDEMAILS_USE_PYNLINER = False is the default value.

Celery

Pynliner can be quite slow when inlining CSS. You can move all the execution to Celery with this setting (default is False):

TEMPLATEDEMAILS_USE_CELERY = True

Please note that the given context is passed to Celery unchanged.

Install

pip install -e http://github.com/philippWassibauer/templated-emails.git#egg=templated-emails

or

pip install templated-emails

Dependencies

  • pynliner

  • cssutils

Follow Me

Metadata

Release files for templated-emails 0.6.9

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for templated-emails 0.6.9
File Size Uploaded
templated-emails-0.6.9.tar.gz 9.1 kB Details

Release files / templated-emails-0.6.9.tar.gz

Download URL templated-emails-0.6.9.tar.gz
Size 9.1 kB
Tags Source
SHA-256 checksum
How to use checksums
a061a6a3008583ea7c2dbded11ae1801a97cae314aa6dc0f1c1cfd568f77764c
BLAKE2b-256 checksum
How to use checksums
b3eaf563fee5b11c88bebe9e2a8248be838f82edd59c2d7f7b57752f3d8aa835
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.6.9 This release

1 release file

0.6.8

1 release file

0.6.7

1 release file

0.6.6

1 release file

0.6.5

1 release file

0.6.4

1 release file

0.6.3

1 release file

0.6.2

1 release file

0.4

0.3

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page