Metadata-Version: 2.1
Name: emark
Version: 1.0.0
Summary: Markdown template based HTML and text emails for Django.
Keywords: Markdown,Django,email,templates,HTML
Author-email: Rust Saiargaliev <fly.amureki@gmail.com>, Johannes Maron <johannes@maron.family>, Mostafa Mohamed <mostafa.anm91@gmail.com>, Jacqueline Kraus <jacquelinekraus1992@gmail.com>
Requires-Python: >=3.10
Description-Content-Type: text/markdown
Classifier: Development Status :: 5 - Production/Stable
Classifier: Programming Language :: Python
Classifier: Environment :: Web Environment
Classifier: License :: OSI Approved :: BSD License
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Topic :: Communications :: Email
Classifier: Topic :: Text Processing :: Markup :: Markdown
Classifier: Topic :: Text Processing :: Markup :: HTML
Classifier: Topic :: Software Development
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Framework :: Django
Classifier: Framework :: Django :: 3.2
Classifier: Framework :: Django :: 4.1
Classifier: Framework :: Django :: 4.2
Requires-Dist: django
Requires-Dist: markdown
Requires-Dist: premailer
Requires-Dist: pytest ; extra == "test"
Requires-Dist: pytest-cov ; extra == "test"
Requires-Dist: pytest-django ; extra == "test"
Requires-Dist: model_bakery ; extra == "test"
Project-URL: Changelog, https://github.com/voiio/emark/releases
Project-URL: Project-URL, https://github.com/voiio/emark
Provides-Extra: test

# Django eMark↓

<img alt="emark logo: envelope with markdown stamp" src="https://raw.githubusercontent.com/voiio/emark/main/emark-logo.svg" width="320" height="170" align="right">

Markdown template based HTML and text emails for Django.

* simple email templates with markdown
* support for HTML and text emails
* i18n support
* built-in UTM tracking
* automatic CSS inliner via [premailer](https://github.com/peterbe/premailer/)

[![PyPi Version](https://img.shields.io/pypi/v/emark.svg)](https://pypi.python.org/pypi/emark/)
[![Test Coverage](https://codecov.io/gh/voiio/emark/branch/main/graph/badge.svg)](https://codecov.io/gh/voiio/emark)
[![GitHub License](https://img.shields.io/github/license/voiio/emark)](https://raw.githubusercontent.com/voiio/emark/master/LICENSE)

## Setup

```ShellSession
python3 -m pip install emark
```

```python
# settings.py
INSTALLED_APPS = [
    'emark',
    # ...
]
```

```ShellSession
python3 manage.py migrate
```

## Usage

```markdown
<!-- myapp/my_message.md -->
# Hello World

Hi {{ user.short_name }}!
```

```python
# myapp/emails.py
from emark.message import MarkdownEmail

class MyMessage(MarkdownEmail):
    subject = "Hello World"
    template_name = "myapp/my_message.md"
```

```python
# myapp/views.py
from . import emails

def my_view(request):
    message = emails.MyMessage.to_user(request.user)
    message.send()
```

### Templates

You can use Django's template engine, just like you usually would.
You can use translations, template tags, filters, blocks, etc.

You may also have a base template, that you inherit form in your individual
emails to provide a consistent salutation and farewell.

```markdown
<!-- base.md -->
{% load static i18n %}
{% block salutation %}Hi {{ user.short_name }}!{% endblock %}

{% block content %}{% endblock %}

{% block farewell %}
{% blocktrans trimmed %}
Best regards,
{{ site_admin }}
{% endblocktrans %}
{% endblock %}

{% block footer %}
Legal footer.
{% endblock %}
```

```markdown
<!-- myapp/email.md -->
{% extends "base.md" %}

{% block content %}
This is the content of the email.
{% endblock %}
```

### Context

The context is passed to the template as a dictionary. Furthermore, you may
override the `get_context_data` method to add additional context variables.

```python
# myapp/emails.py
from emark.message import MarkdownEmail

class MyMessage(MarkdownEmail):
    subject = "Hello World"
    template_name = "myapp/email.md"

    def get_context_data(self):
        context = super().get_context_data()
        context["my_variable"] = "Hello World"
        return context
```

### Tracking

Every `MarkdownEmail` subclass comes with automatic UTM tracking.
UTM parameters are added to all links in the email. Existing UTM params on link
that have been explicitly set, are not overridden. The default parameters are:

* `utm_source`: `website`
* `utm_medium`: `email`
* `utm_campaign`: `{{ EMAIL_CLASS_NAME }}`

The global UTM parameters can be overridden via the `EMARK_UTM_PARAMS` setting,
which is a dictionary of parameters:

```python
# settings.py
EMARK_UTM_PARAMS = {
    "utm_source": "website",  # default
    "utm_medium": "email",  # default
}
```

You may also change the UTM parameters by overriding the `get_utm_params`
or passing a `utm_params` dictionary to class constructor.

```python
# myapp/emails.py
from emark.message import MarkdownEmail


class MyMessage(MarkdownEmail):
  subject = "Hello World"
  template_name = "myapp/email.md"

  # override the parameters for this email class
  def get_utm_params(self):
    return {
      "utm_source": "myapp",
      "utm_medium": "email",
      "utm_campaign": "my-campaign",
    }


# or alternatively during instantiation
MyMessage(utm_params={"utm_campaign": "my-other-campaign"}).send()
```

## Credits

- Django eMark uses modified version of [Responsive HTML Email Template](https://github.com/leemunroe/responsive-html-email-template/) as a base template
- For CSS inlining, Django eMark uses [premailer](https://github.com/peterbe/premailer/)

