GithubHelp home page GithubHelp logo

kminkov / django-mail-templated Goto Github PK

View Code? Open in Web Editor NEW

This project forked from artemrizhov/django-mail-templated

1.0 2.0 2.0 105 KB

Send emails with Django template system

License: MIT License

Python 92.96% HTML 5.88% Smarty 1.16%

django-mail-templated's Introduction

Django-Mail-Templated

Info:Send emails using Django template system
Author: Artem Rizhov (https://github.com/artemrizhov)

Overview

This is a tiny wrapper around the standard EmailMessage class and send_mail() function. Just pass template_name and context as the first parameters then use as normal.

Installation

Run:

$ pip install django-mail-templated

And register the app in your settings file:

INSTALLED_APPS = (
    ...
    'mail_templated'
)

Usage

Write a template to send a plain text message. Note that first and last newline will be removed:

{% block subject %}
Hello {{ user.name }}
{% endblock %}

{% block body %}
This is a plain text message.
{% endblock %}

Or for an html message:

{% block subject %}
Hello {{ user.name }}
{% endblock %}

{% block html %}
This is an <strong>html</strong> message.
{% endblock %}

Or for a multipart message you can use both blocks:

{% block subject %}
Hello {{ user.name }}
{% endblock %}

{% block body %}
This is a plain text message.
{% endblock %}

{% block html %}
This is an <strong>html</strong> message.
{% endblock %}

Or leave out some block to set it manually later with EmailMessage class:

{% block body %}
This is a plain text message.
{% endblock %}

Now you can send it:

from mail_templated import send_mail
send_mail('email/hello.tpl', {'user': user}, from_email, [user.email])

Or if you wish to add more control over message creation then use the class form:

from mail_templated import EmailMessage
message = EmailMessage('email/hello.tpl', {'user': user}, to=[user.email])
# ... attach a file, etc
message.send()

That's all. Please create an issue at GitHub if you have any notes, ...or just email :)

django-mail-templated's People

Contributors

almost avatar arjandepooter avatar artemrizhov avatar kminkov avatar suciu0313 avatar

Stargazers

 avatar

Watchers

 avatar  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.