Skip to content

Commit

Permalink
Merge pull request BradWhittington#31 from danifus/master
Browse files Browse the repository at this point in the history
Documentation enhancement and small fixes
  • Loading branch information
pydanny committed Nov 2, 2015
2 parents d5f66d0 + b108d22 commit 70ab6b0
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,17 @@ Install django-mailgun::

pip install django-mailgun

Add the following to your settings.py::
Add the following to your ``settings.py``::

EMAIL_BACKEND = 'django_mailgun.MailgunBackend'
MAILGUN_ACCESS_KEY = 'ACCESS-KEY'
MAILGUN_SERVER_NAME = 'SERVER-NAME'

Replace ``ACCESS-KEY`` with the "API-KEY" value from your Mailgun account details and
``SERVER-NAME`` with the last part of your "API Base URL"
(eg. https://api.mailgun.net/v3/**<your_server_name>**), also found in your Mailgun
account details.

Now, when you use ``django.core.mail.send_mail``, Mailgun will send the messages.

.. _Builtin Email Error Reporting: http://docs.djangoproject.com/en/1.2/howto/error-reporting/
Expand All @@ -36,15 +41,15 @@ Passing user-specific data
Mailgun also includes the ability to send emails to a group of recipients via a single
API call (https://documentation.mailgun.com/user_manual.html#batch-sending). To make use of this,
you need to pass Recipient Variables along with your API call. To do so with Django-Mailgun,
add a valid json string to the `extra_headers` attribute of EmailMessage and Django-Mailgun will
add a valid JSON string to the ``extra_headers`` attribute of ``EmailMessage`` and Django-Mailgun will
remove the string from the headers and send it appropriately. For example::

email = EmailMessage('Hi!', 'Cool message for %recipient.first_name%', '[email protected]', [[email protected], [email protected]])
email.extra_headers['recipient_variables'] = '{"[email protected]":{"first_name":"Joe"}, "[email protected]":{"first_name":"Jane"}}'
email.send()

When Jane receives her email, its body should read 'Cool message for Jane', and Joe will see
'Cool messagae for Joe'.
'Cool message for Joe'.

Analytics and other tracking features
-------------------------------------
Expand All @@ -53,7 +58,7 @@ Mailgun provides the ability to track certain events that concern your emails. T
API exposes these options (see https://documentation.mailgun.com/api-sending.html#sending). These
options can also be passed to Mailgun's SMTP server (see "Passing Sending Options" under
https://documentation.mailgun.com/user_manual.html#sending-via-smtp). If you add
any of the SMTP options to the `extra_headers` attribute of EmailMessage, Django-Mailgun
any of the SMTP options to the ``extra_headers`` attribute of ``EmailMessage``, Django-Mailgun
will map those values over to the appropriate API parameter. For example::

email = EmailMessage('Hi!', 'Cool message for Joe', '[email protected]', [[email protected]])
Expand Down

0 comments on commit 70ab6b0

Please sign in to comment.