Giter Site home page Giter Site logo

dpinnock / templated-emails Goto Github PK

View Code? Open in Web Editor NEW

This project forked from philippwassibauer/templated-emails

0.0 1.0 0.0 97 KB

A simple app (that works similar to django-notification) that allows you to send emails by specifying a short.txt (subject), email.txt (plain text), and email.html (html email, optional) in a folder. When you send the email you only have to specify the folder and the context.

License: MIT License

templated-emails's Introduction

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(["[email protected]"], "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

templated-emails's People

Contributors

kmike avatar hannesstruss avatar wrar avatar bradbeattie avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.