<commit_before>==================
Django Post Office
==================

Django Post Office is a simple app to send and manage your emails in Django.
Some awesome features are:

* Allows you to send email asynchronously
* Multi backend support
* Supports HTML email
* Supports database based email templates
* Built in scheduling support
* Works well with task queues like `RQ <http://python-rq.org>`_ or `Celery <http://www.celeryproject.org>`_
* Uses multiprocessing to send a large number of emails in parallel
* Supports multilingual email templates (i18n)


Dependencies
============

* `django >= 1.4 <http://djangoproject.com/>`_
* `django-jsonfield <https://github.com/bradjasper/django-jsonfield>`_


Installation
============

|Build Status|


* Install from PyPI (or you `manually download from PyPI <http://pypi.python.org/pypi/django-post_office>`_)::

    pip install django-post_office

* Add ``post_office`` to your INSTALLED_APPS in django's ``settings.py``:

.. code-block:: python

    INSTALLED_APPS = (
        # other apps
        "post_office",
    )

* Run ``syncdb``::

    python manage.py syncdb

* Set ``post_office.EmailBackend`` as your ``EMAIL_BACKEND`` in django's ``settings.py``::

    EMAIL_BACKEND = 'post_office.EmailBackend'

If you're still on Django <= 1.6 and use South to manage your migrations,
you'll need to put the following in ``settings.py``:

.. code-block:: python

    SOUTH_MIGRATION_MODULES = {
        "post_office": "post_office.south_migrations",
    }


Quickstart
==========

Send a simple email is really easy:

.. code-block:: python

    from post_office import mail

    mail.send(
        '<EMAIL>', # List of email addresses also accepted
        '<EMAIL>',
        subject='My email',
        message='Hi there!',
        html_message='Hi <strong>there</strong>!',
    )    


If you want to use templates, ensure that Django's admin interface is enabled. Create an
``EmailTemplate`` instance via ``admin`` and do the following:

.. code-block:: python

    from post_office import mail

    mail.send(
        '<EMAIL>', # List of email addresses also accepted
        '<EMAIL>',
        template='welcome_email', # Could be an EmailTemplate instance or name
        context={'foo': 'bar'},
    )

The above command will put your email on the queue so you can use the
command in your webapp without slowing down the request/response cycle too much.
To actually send them out, run ``python manage.py send_queued_mail``.
You can schedule this management command to run regularly via cron::

    * * * * * (/usr/bin/python manage.py send_queued_mail >> send_mail.log 2>&1)


Usage
=====

mail.send()
-----------

``mail.send`` is the most important function in this library, it takes these
arguments:

+-------------------+----------+-------------------------------------------------+
| Argument          | Required | Description                                     |
+-------------------+----------+-------------------------------------------------+
| recipients        | Yes      | list of recipient email addresses               |
+-------------------+----------+-------------------------------------------------+
| sender            | No       | Defaults to ``settings.DEFAULT_FROM_EMAIL``,    |
|                   |          | display name is allowed (``John <<EMAIL>>``) |
+-------------------+----------+-------------------------------------------------+
| subject           | No       | Email subject (if ``template`` is not specified)|
+-------------------+----------+-------------------------------------------------+
| message           | No       | Email content (if ``template`` is not specified)|
+-------------------+----------+-------------------------------------------------+
| html_message      | No       | HTML content (if ``template`` is not specified) |
+-------------------+----------+-------------------------------------------------+
| template          | No       | ``EmailTemplate`` instance or name              |
+-------------------+----------+-------------------------------------------------+
| language          | No       | Language in which you want to send the email in |
|                   |          | (if you have multilingual email templates.)     |
+-------------------+----------+-------------------------------------------------+
| cc                | No       | list emails, will appear in ``cc`` field        |
+-------------------+----------+-------------------------------------------------+
| bcc               | No       | list of emails, will appear in `bcc` field      |
+-------------------+----------+-------------------------------------------------+
| attachments       | No       | Email attachments - A dictionary where the keys |
|                   |          | are the filenames and the values are either:    |
|                   |          |                                                 |
|                   |          | * files                                         |
|                   |          | * file-like objects                             |
|                   |          | * full path of the file                         |
+-------------------+----------+-------------------------------------------------+
| context           | No       | A dictionary, used to render templated email    |
+-------------------+----------+-------------------------------------------------+
| headers           | No       | A dictionary of extra headers on the message    |
+-------------------+----------+-------------------------------------------------+
| scheduled_time    | No       | A date/datetime object indicating when the email|
|                   |          | should be sent                                  |
+-------------------+----------+-------------------------------------------------+
| priority          | No       | ``high``, ``medium``, ``low`` or ``now``        |
|                   |          | (send_immediately)                              |
+-------------------+----------+-------------------------------------------------+
| backend           | No       | Alias of the backend you want to use.           |
|                   |          | ``default`` will be used if not specified.      |
+-------------------+----------+-------------------------------------------------+
| render_on_delivery| No       | Setting this to ``True`` causes email to be     |
|                   |          | lazily rendered during delivery. ``template``   |
|                   |          | is required when ``render_on_delivery`` is True.|
|                   |          | This way content is never stored in the DB.     |
|                   |          | May result in significat space savings.         |
+-------------------+----------+-------------------------------------------------+


Here are a few examples.
<commit_msg>Fix typo<commit_after>==================
Django Post Office
==================

Django Post Office is a simple app to send and manage your emails in Django.
Some awesome features are:

* Allows you to send email asynchronously
* Multi backend support
* Supports HTML email
* Supports database based email templates
* Built in scheduling support
* Works well with task queues like `RQ <http://python-rq.org>`_ or `Celery <http://www.celeryproject.org>`_
* Uses multiprocessing to send a large number of emails in parallel
* Supports multilingual email templates (i18n)


Dependencies
============

* `django >= 1.4 <http://djangoproject.com/>`_
* `django-jsonfield <https://github.com/bradjasper/django-jsonfield>`_


Installation
============

|Build Status|


* Install from PyPI (or you `manually download from PyPI <http://pypi.python.org/pypi/django-post_office>`_)::

    pip install django-post_office

* Add ``post_office`` to your INSTALLED_APPS in django's ``settings.py``:

.. code-block:: python

    INSTALLED_APPS = (
        # other apps
        "post_office",
    )

* Run ``syncdb``::

    python manage.py syncdb

* Set ``post_office.EmailBackend`` as your ``EMAIL_BACKEND`` in django's ``settings.py``::

    EMAIL_BACKEND = 'post_office.EmailBackend'

If you're still on Django <= 1.6 and use South to manage your migrations,
you'll need to put the following in ``settings.py``:

.. code-block:: python

    SOUTH_MIGRATION_MODULES = {
        "post_office": "post_office.south_migrations",
    }


Quickstart
==========

Send a simple email is really easy:

.. code-block:: python

    from post_office import mail

    mail.send(
        '<EMAIL>', # List of email addresses also accepted
        '<EMAIL>',
        subject='My email',
        message='Hi there!',
        html_message='Hi <strong>there</strong>!',
    )    


If you want to use templates, ensure that Django's admin interface is enabled. Create an
``EmailTemplate`` instance via ``admin`` and do the following:

.. code-block:: python

    from post_office import mail

    mail.send(
        '<EMAIL>', # List of email addresses also accepted
        '<EMAIL>',
        template='welcome_email', # Could be an EmailTemplate instance or name
        context={'foo': 'bar'},
    )

The above command will put your email on the queue so you can use the
command in your webapp without slowing down the request/response cycle too much.
To actually send them out, run ``python manage.py send_queued_mail``.
You can schedule this management command to run regularly via cron::

    * * * * * (/usr/bin/python manage.py send_queued_mail >> send_mail.log 2>&1)


Usage
=====

mail.send()
-----------

``mail.send`` is the most important function in this library, it takes these
arguments:

+-------------------+----------+-------------------------------------------------+
| Argument          | Required | Description                                     |
+-------------------+----------+-------------------------------------------------+
| recipients        | Yes      | list of recipient email addresses               |
+-------------------+----------+-------------------------------------------------+
| sender            | No       | Defaults to ``settings.DEFAULT_FROM_EMAIL``,    |
|                   |          | display name is allowed (``John <<EMAIL>>``) |
+-------------------+----------+-------------------------------------------------+
| subject           | No       | Email subject (if ``template`` is not specified)|
+-------------------+----------+-------------------------------------------------+
| message           | No       | Email content (if ``template`` is not specified)|
+-------------------+----------+-------------------------------------------------+
| html_message      | No       | HTML content (if ``template`` is not specified) |
+-------------------+----------+-------------------------------------------------+
| template          | No       | ``EmailTemplate`` instance or name              |
+-------------------+----------+-------------------------------------------------+
| language          | No       | Language in which you want to send the email in |
|                   |          | (if you have multilingual email templates.)     |
+-------------------+----------+-------------------------------------------------+
| cc                | No       | list emails, will appear in ``cc`` field        |
+-------------------+----------+-------------------------------------------------+
| bcc               | No       | list of emails, will appear in `bcc` field      |
+-------------------+----------+-------------------------------------------------+
| attachments       | No       | Email attachments - A dictionary where the keys |
|                   |          | are the filenames and the values are either:    |
|                   |          |                                                 |
|                   |          | * files                                         |
|                   |          | * file-like objects                             |
|                   |          | * full path of the file                         |
+-------------------+----------+-------------------------------------------------+
| context           | No       | A dictionary, used to render templated email    |
+-------------------+----------+-------------------------------------------------+
| headers           | No       | A dictionary of extra headers on the message    |
+-------------------+----------+-------------------------------------------------+
| scheduled_time    | No       | A date/datetime object indicating when the email|
|                   |          | should be sent                                  |
+-------------------+----------+-------------------------------------------------+
| priority          | No       | ``high``, ``medium``, ``low`` or ``now``        |
|                   |          | (send_immediately)                              |
+-------------------+----------+-------------------------------------------------+
| backend           | No       | Alias of the backend you want to use.           |
|                   |          | ``default`` will be used if not specified.      |
+-------------------+----------+-------------------------------------------------+
| render_on_delivery| No       | Setting this to ``True`` causes email to be     |
|                   |          | lazily rendered during delivery. ``template``   |
|                   |          | is required when ``render_on_delivery`` is True.|
|                   |          | This way content is never stored in the DB.     |
|                   |          | May result in significant space savings.        |
+-------------------+----------+-------------------------------------------------+


Here are a few examples.

{'fraction_non_alphanumeric': 0.30107057024251693, 'fraction_numerical': 0.0011652465224674096, 'mean_word_length': 1.0603150787696924, 'pattern_counts': {'":': 2, '<': 31, '<?xml version=': 0, '>': 37, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 20, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6215887', 'n_tokens_mistral': 3048, 'n_tokens_neox': 2871, 'n_words': 1011}