emark


Nameemark JSON
Version 2.1.3 PyPI version JSON
download
home_pageNone
SummaryMarkdown template based HTML and text emails for Django.
upload_time2024-10-18 15:03:55
maintainerNone
docs_urlNone
authorNone
requires_python>=3.10
licenseNone
keywords markdown django email templates html
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 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
* built-in sent, open and click 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

#### Sent, Open & Click Tracking

Django eMark comes with built-in tracking for sent, open and click events.
The tracking is done via a tracking pixel and a redirect view.

As an added bonus, this feature also comes with an open-in-browser link that
allows the user to view the email in their browser if their email client does
not support HTML emails.

This feature is disabled by default. To enable it, you need to use a separate email
backend. This backend will send the email via SMTP and also add the tracking
pixel and redirect view. However, it will send a separate email for each
recipient, which may not be desirable in all cases.

```python
# settings.py
EMAIL_BACKEND = "emark.backends.TrackingSMTPEmailBackend"
```

Furthermore, you need to add the tracking view to your `urls.py`:

```python
# urls.py
from django.urls import include, path

urlpatterns = [
    # … other urls
    path("emark/", include("emark.urls")),
]
```

You will need to provide a domain name for the tracking pixel and redirect view.
This can be done via the `DOMAIN` setting:

```python
# settings.py
EMARK = {
    "DOMAIN": "example.com"
}
```

If the site framework is installed and no settings are provided,
the domain will be automatically set to the current site's domain.

The tracking data is stored in the database. You need to run migrations to
create the necessary tables:

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

You can analyze the tracking data via the tables `emark_sent`, `emark_open` and
`emark_click`.

#### UTM 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()
```

## Development

Pretty HTML emails are great, unless they spam your console during development.
To prevent this, you can use the `ConsoleEmailBackend`:

```python
# settings.py
EMAIL_BACKEND = "emark.backends.ConsoleEmailBackend"
```

The `ConsoleEmailBackend` will only print the plain text version of the email.

### Email Dashboard

Django eMark comes with a simple email dashboard to preview your templates.

To enable the dashboard, add the app to your `INSTALLED_APPS` setting

```python
# settings.py
INSTALLED_APPS = [
    # ...
    "emark",
    "emark.contrib.dashboard",  # needs to be added before Django's admin app
    # ...
    "django.contrib.admin",  # required for the dashboard
    # ...
]
```

and add the following to your `urls.py`:

```python
# urls.py
from django.urls import include, path


urlpatterns = [
    # … other urls
    path("emark/", include([
        path("", include("emark.urls")),
        path("dashboard/", include("emark.contrib.dashboard.urls")),
    ])),
]
```

Next you need to register the email classes you want to preview in the dashboard:

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

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

## 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/)


            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "emark",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.10",
    "maintainer_email": null,
    "keywords": "Markdown, Django, email, templates, HTML",
    "author": null,
    "author_email": "Rust Saiargaliev <fly.amureki@gmail.com>, Johannes Maron <johannes@maron.family>, Mostafa Mohamed <mostafa.anm91@gmail.com>, Jacqueline Kraus <jacquelinekraus1992@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/46/58/5175738614f3ffdc94f77db8f1209de40dda903cba9d20031d79b4c80b70/emark-2.1.3.tar.gz",
    "platform": null,
    "description": "# Django eMark\u2193\n\n<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\">\n\nMarkdown template based HTML and text emails for Django.\n\n* simple email templates with markdown\n* support for HTML and text emails\n* i18n support\n* built-in UTM tracking\n* built-in sent, open and click tracking\n* automatic CSS inliner via [premailer](https://github.com/peterbe/premailer/)\n\n[![PyPi Version](https://img.shields.io/pypi/v/emark.svg)](https://pypi.python.org/pypi/emark/)\n[![Test Coverage](https://codecov.io/gh/voiio/emark/branch/main/graph/badge.svg)](https://codecov.io/gh/voiio/emark)\n[![GitHub License](https://img.shields.io/github/license/voiio/emark)](https://raw.githubusercontent.com/voiio/emark/master/LICENSE)\n\n## Setup\n\n```ShellSession\npython3 -m pip install emark\n```\n\n```python\n# settings.py\nINSTALLED_APPS = [\n    'emark',\n    # ...\n]\n```\n\n```ShellSession\npython3 manage.py migrate\n```\n\n## Usage\n\n```markdown\n<!-- myapp/my_message.md -->\n# Hello World\n\nHi {{ user.short_name }}!\n```\n\n```python\n# myapp/emails.py\nfrom emark.message import MarkdownEmail\n\nclass MyMessage(MarkdownEmail):\n    subject = \"Hello World\"\n    template_name = \"myapp/my_message.md\"\n```\n\n```python\n# myapp/views.py\nfrom . import emails\n\ndef my_view(request):\n    message = emails.MyMessage.to_user(request.user)\n    message.send()\n```\n\n### Templates\n\nYou can use Django's template engine, just like you usually would.\nYou can use translations, template tags, filters, blocks, etc.\n\nYou may also have a base template, that you inherit form in your individual\nemails to provide a consistent salutation and farewell.\n\n```markdown\n<!-- base.md -->\n{% load static i18n %}\n{% block salutation %}Hi {{ user.short_name }}!{% endblock %}\n\n{% block content %}{% endblock %}\n\n{% block farewell %}\n{% blocktrans trimmed %}\nBest regards,\n{{ site_admin }}\n{% endblocktrans %}\n{% endblock %}\n\n{% block footer %}\nLegal footer.\n{% endblock %}\n```\n\n```markdown\n<!-- myapp/email.md -->\n{% extends \"base.md\" %}\n\n{% block content %}\nThis is the content of the email.\n{% endblock %}\n```\n\n### Context\n\nThe context is passed to the template as a dictionary. Furthermore, you may\noverride the `get_context_data` method to add additional context variables.\n\n```python\n# myapp/emails.py\nfrom emark.message import MarkdownEmail\n\nclass MyMessage(MarkdownEmail):\n    subject = \"Hello World\"\n    template_name = \"myapp/email.md\"\n\n    def get_context_data(self):\n        context = super().get_context_data()\n        context[\"my_variable\"] = \"Hello World\"\n        return context\n```\n\n### Tracking\n\n#### Sent, Open & Click Tracking\n\nDjango eMark comes with built-in tracking for sent, open and click events.\nThe tracking is done via a tracking pixel and a redirect view.\n\nAs an added bonus, this feature also comes with an open-in-browser link that\nallows the user to view the email in their browser if their email client does\nnot support HTML emails.\n\nThis feature is disabled by default. To enable it, you need to use a separate email\nbackend. This backend will send the email via SMTP and also add the tracking\npixel and redirect view. However, it will send a separate email for each\nrecipient, which may not be desirable in all cases.\n\n```python\n# settings.py\nEMAIL_BACKEND = \"emark.backends.TrackingSMTPEmailBackend\"\n```\n\nFurthermore, you need to add the tracking view to your `urls.py`:\n\n```python\n# urls.py\nfrom django.urls import include, path\n\nurlpatterns = [\n    # \u2026 other urls\n    path(\"emark/\", include(\"emark.urls\")),\n]\n```\n\nYou will need to provide a domain name for the tracking pixel and redirect view.\nThis can be done via the `DOMAIN` setting:\n\n```python\n# settings.py\nEMARK = {\n    \"DOMAIN\": \"example.com\"\n}\n```\n\nIf the site framework is installed and no settings are provided,\nthe domain will be automatically set to the current site's domain.\n\nThe tracking data is stored in the database. You need to run migrations to\ncreate the necessary tables:\n\n```ShellSession\npython3 manage.py migrate\n```\n\nYou can analyze the tracking data via the tables `emark_sent`, `emark_open` and\n`emark_click`.\n\n#### UTM Tracking\n\nEvery `MarkdownEmail` subclass comes with automatic UTM tracking.\nUTM parameters are added to all links in the email. Existing UTM params on link\nthat have been explicitly set, are not overridden. The default parameters are:\n\n* `utm_source`: `website`\n* `utm_medium`: `email`\n* `utm_campaign`: `{{ EMAIL_CLASS_NAME }}`\n\nThe global UTM parameters can be overridden via the `EMARK_UTM_PARAMS` setting,\nwhich is a dictionary of parameters:\n\n```python\n# settings.py\nEMARK = {\n  \"UTM_PARAMS\": {\n      \"utm_source\": \"website\",  # default\n      \"utm_medium\": \"email\",  # default\n  }\n}\n```\n\nYou may also change the UTM parameters by overriding the `get_utm_params`\nor passing a `utm_params` dictionary to class constructor.\n\n```python\n# myapp/emails.py\nfrom emark.message import MarkdownEmail\n\n\nclass MyMessage(MarkdownEmail):\n  subject = \"Hello World\"\n  template_name = \"myapp/email.md\"\n\n  # override the parameters for this email class\n  def get_utm_params(self):\n    return {\n      \"utm_source\": \"myapp\",\n      \"utm_medium\": \"email\",\n      \"utm_campaign\": \"my-campaign\",\n    }\n\n\n# or alternatively during instantiation\nMyMessage(utm_params={\"utm_campaign\": \"my-other-campaign\"}).send()\n```\n\n## Development\n\nPretty HTML emails are great, unless they spam your console during development.\nTo prevent this, you can use the `ConsoleEmailBackend`:\n\n```python\n# settings.py\nEMAIL_BACKEND = \"emark.backends.ConsoleEmailBackend\"\n```\n\nThe `ConsoleEmailBackend` will only print the plain text version of the email.\n\n### Email Dashboard\n\nDjango eMark comes with a simple email dashboard to preview your templates.\n\nTo enable the dashboard, add the app to your `INSTALLED_APPS` setting\n\n```python\n# settings.py\nINSTALLED_APPS = [\n    # ...\n    \"emark\",\n    \"emark.contrib.dashboard\",  # needs to be added before Django's admin app\n    # ...\n    \"django.contrib.admin\",  # required for the dashboard\n    # ...\n]\n```\n\nand add the following to your `urls.py`:\n\n```python\n# urls.py\nfrom django.urls import include, path\n\n\nurlpatterns = [\n    # \u2026 other urls\n    path(\"emark/\", include([\n        path(\"\", include(\"emark.urls\")),\n        path(\"dashboard/\", include(\"emark.contrib.dashboard.urls\")),\n    ])),\n]\n```\n\nNext you need to register the email classes you want to preview in the dashboard:\n\n```python\n# myapp/emails.py\nfrom emark.message import MarkdownEmail\nfrom emark.contrib import dashboard\n\n@dashboard.register\nclass MyMessage(MarkdownEmail):\n    subject = \"Hello World\"\n    template_name = \"myapp/email.md\"\n```\n\n## Credits\n\n- Django eMark uses modified version of [Responsive HTML Email Template](https://github.com/leemunroe/responsive-html-email-template/) as a base template\n- For CSS inlining, Django eMark uses [premailer](https://github.com/peterbe/premailer/)\n\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "Markdown template based HTML and text emails for Django.",
    "version": "2.1.3",
    "project_urls": {
        "Changelog": "https://github.com/voiio/emark/releases",
        "Project-URL": "https://github.com/voiio/emark"
    },
    "split_keywords": [
        "markdown",
        " django",
        " email",
        " templates",
        " html"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a27957282878ac4bba80cc8402710120b5a26b37759fb6f03e934d5bfee49d9b",
                "md5": "a85533eba8cf239409745bdf69cc2ac6",
                "sha256": "77f7aed58e15cb5c1186c18ec249d16dcf3a00e209f8473de768d03de97594c9"
            },
            "downloads": -1,
            "filename": "emark-2.1.3-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "a85533eba8cf239409745bdf69cc2ac6",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10",
            "size": 24579,
            "upload_time": "2024-10-18T15:03:54",
            "upload_time_iso_8601": "2024-10-18T15:03:54.346730Z",
            "url": "https://files.pythonhosted.org/packages/a2/79/57282878ac4bba80cc8402710120b5a26b37759fb6f03e934d5bfee49d9b/emark-2.1.3-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "46585175738614f3ffdc94f77db8f1209de40dda903cba9d20031d79b4c80b70",
                "md5": "39f7b54de8dc5b3179cca1959e93659e",
                "sha256": "1278dc0d9a8e1f584d028484f0e8c925b718813e0224680bb8c9819612911d34"
            },
            "downloads": -1,
            "filename": "emark-2.1.3.tar.gz",
            "has_sig": false,
            "md5_digest": "39f7b54de8dc5b3179cca1959e93659e",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10",
            "size": 20977,
            "upload_time": "2024-10-18T15:03:55",
            "upload_time_iso_8601": "2024-10-18T15:03:55.421417Z",
            "url": "https://files.pythonhosted.org/packages/46/58/5175738614f3ffdc94f77db8f1209de40dda903cba9d20031d79b4c80b70/emark-2.1.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-10-18 15:03:55",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "voiio",
    "github_project": "emark",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "emark"
}
        
Elapsed time: 8.72049s