templatemail


Nametemplatemail JSON
Version 1.1.0 PyPI version JSON
download
home_pagehttps://github.com/kkinder/templatemail
SummaryTemplated Email for Python Projects with Jinja2
upload_time2024-06-25 11:40:18
maintainerNone
docs_urlNone
authorKen Kinder
requires_python<4.0,>=3.9
licenseApache
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI
coveralls test coverage No coveralls.
            ![Build Status](https://travis-ci.org/kkinder/templatemail.svg?branch=master)

# Welcome to TemplateMail

TemplateMail is a simple Python library that solves most projects' email templating and delivery needs with minimal hassle. Suppose you want to send a welcome email to a new user using Mailgun:

```python
import templatemail
import templatemail.engines.mailgun

# Credentials for Mailgun
MAILGUN_API_KEY = 'YOUR API KEY'
MAILGUN_DOMAIN = 'MAILGUN_DOMAIN'

# The engine is in charge of sending email using a backend system.
engine = templatemail.engines.mailgun.MailgunDeliveryEngine(
    api_key=MAILGUN_API_KEY,
    domain_name=MAILGUN_DOMAIN)
    
# The mailer is in charge of rendering templates and sending them using an engine.
mailer = templatemail.TemplateMail(
    template_dirs=['email_templates'],
    delivery_engine=engine)

# Using the two, you can send templates.
template_name = 'welcome.html'
result = mailer.send_email(
    to_addresses=['test@example.com'],
    from_address='from@example.com',
    template_name=template_name,
    user_name='Ken'
)
```

`welcome.html` is an *email template* used to render the subject, html, and text versions of an email. Let's have a look at `email_templates/welcome.html`:

```jinja2
{% block subject %}Welcome to our system{% endblock %}
{% block html_body %}
<h1>Welcome to our system, {{ user_name }}</h1>
<p>We think you'll really enjoy it here.</p>
{% endblock %}
{% block text_body %}
Welcome to our system, {{ user_name }}
--------------------------------------------

We think you'll really enjoy it here.
{% endblock %}
```

The `subject` block renders the subject, while `html_body` and `text_body` render the HTML and text versions of the email respectively. The work of composing the correct mime envelope, as well as delivery, is handled by an engine. At this time, TemplateMail has native Mailgun and SMTP backends, however you are also free to write your own. (See [Writing your own engine](/engines/#writing-your-own-engine))

It's that simple.

## Installation

You can install templatemail like any other Python module.

```pip install templatemail```

**NOTE**: Only Python 3 is supported.

## Read More

[Read the documentation online](https://templatemail.readthedocs.io/en/latest/) at Read The Docs.

## Get in touch
Have a pull request or an issue? [Use Github](https://github.com/kkinder/templatemail).

## Legal stuff
© Copyright 2019 Ken Kinder. Includes work from Mailgun, which is © Copyright 2014 Mailgun.

TemplateMail is licensed under the Apache 2.0 license. See LICENSE for details.

Includes templates from the Mailgun Responsive Templates repository. See LICENSE-mailgun-templates for details on its license.


            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/kkinder/templatemail",
    "name": "templatemail",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0,>=3.9",
    "maintainer_email": null,
    "keywords": null,
    "author": "Ken Kinder",
    "author_email": "ken+github@kkinder.com",
    "download_url": "https://files.pythonhosted.org/packages/d3/bf/a4c0892c2900b06ead523dea059452730f07b12f3ff42e04340cd3ddea26/templatemail-1.1.0.tar.gz",
    "platform": null,
    "description": "![Build Status](https://travis-ci.org/kkinder/templatemail.svg?branch=master)\n\n# Welcome to TemplateMail\n\nTemplateMail is a simple Python library that solves most projects' email templating and delivery needs with minimal hassle. Suppose you want to send a welcome email to a new user using Mailgun:\n\n```python\nimport templatemail\nimport templatemail.engines.mailgun\n\n# Credentials for Mailgun\nMAILGUN_API_KEY = 'YOUR API KEY'\nMAILGUN_DOMAIN = 'MAILGUN_DOMAIN'\n\n# The engine is in charge of sending email using a backend system.\nengine = templatemail.engines.mailgun.MailgunDeliveryEngine(\n    api_key=MAILGUN_API_KEY,\n    domain_name=MAILGUN_DOMAIN)\n    \n# The mailer is in charge of rendering templates and sending them using an engine.\nmailer = templatemail.TemplateMail(\n    template_dirs=['email_templates'],\n    delivery_engine=engine)\n\n# Using the two, you can send templates.\ntemplate_name = 'welcome.html'\nresult = mailer.send_email(\n    to_addresses=['test@example.com'],\n    from_address='from@example.com',\n    template_name=template_name,\n    user_name='Ken'\n)\n```\n\n`welcome.html` is an *email template* used to render the subject, html, and text versions of an email. Let's have a look at `email_templates/welcome.html`:\n\n```jinja2\n{% block subject %}Welcome to our system{% endblock %}\n{% block html_body %}\n<h1>Welcome to our system, {{ user_name }}</h1>\n<p>We think you'll really enjoy it here.</p>\n{% endblock %}\n{% block text_body %}\nWelcome to our system, {{ user_name }}\n--------------------------------------------\n\nWe think you'll really enjoy it here.\n{% endblock %}\n```\n\nThe `subject` block renders the subject, while `html_body` and `text_body` render the HTML and text versions of the email respectively. The work of composing the correct mime envelope, as well as delivery, is handled by an engine. At this time, TemplateMail has native Mailgun and SMTP backends, however you are also free to write your own. (See [Writing your own engine](/engines/#writing-your-own-engine))\n\nIt's that simple.\n\n## Installation\n\nYou can install templatemail like any other Python module.\n\n```pip install templatemail```\n\n**NOTE**: Only Python 3 is supported.\n\n## Read More\n\n[Read the documentation online](https://templatemail.readthedocs.io/en/latest/) at Read The Docs.\n\n## Get in touch\nHave a pull request or an issue? [Use Github](https://github.com/kkinder/templatemail).\n\n## Legal stuff\n\u00a9 Copyright 2019 Ken Kinder. Includes work from Mailgun, which is \u00a9 Copyright 2014 Mailgun.\n\nTemplateMail is licensed under the Apache 2.0 license. See LICENSE for details.\n\nIncludes templates from the Mailgun Responsive Templates repository. See LICENSE-mailgun-templates for details on its license.\n\n",
    "bugtrack_url": null,
    "license": "Apache",
    "summary": "Templated Email for Python Projects with Jinja2",
    "version": "1.1.0",
    "project_urls": {
        "Homepage": "https://github.com/kkinder/templatemail"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "0c36929b0f215ce7b2c310bda9e13d110b6460bc079a368b7da90bb095be9c32",
                "md5": "26973fc9c1719c0b6598f563ab5ebb93",
                "sha256": "3dd4913f4021477fc3a6ee39b96835fd896e1f86c09e996b43ba485485010aa4"
            },
            "downloads": -1,
            "filename": "templatemail-1.1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "26973fc9c1719c0b6598f563ab5ebb93",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.9",
            "size": 17331,
            "upload_time": "2024-06-25T11:40:17",
            "upload_time_iso_8601": "2024-06-25T11:40:17.203913Z",
            "url": "https://files.pythonhosted.org/packages/0c/36/929b0f215ce7b2c310bda9e13d110b6460bc079a368b7da90bb095be9c32/templatemail-1.1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "d3bfa4c0892c2900b06ead523dea059452730f07b12f3ff42e04340cd3ddea26",
                "md5": "55696dcbd02bafe62aedf561b449834b",
                "sha256": "84979156922f573c32ec41c53c17618924f3c07a8fd3bcd0975e55579291c174"
            },
            "downloads": -1,
            "filename": "templatemail-1.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "55696dcbd02bafe62aedf561b449834b",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.9",
            "size": 13648,
            "upload_time": "2024-06-25T11:40:18",
            "upload_time_iso_8601": "2024-06-25T11:40:18.460047Z",
            "url": "https://files.pythonhosted.org/packages/d3/bf/a4c0892c2900b06ead523dea059452730f07b12f3ff42e04340cd3ddea26/templatemail-1.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-06-25 11:40:18",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "kkinder",
    "github_project": "templatemail",
    "travis_ci": true,
    "coveralls": false,
    "github_actions": true,
    "lcname": "templatemail"
}
        
Elapsed time: 0.25746s