Skip to main content

Send email using Mailgun with Mailgun specific attributes.

It also includes an API-compatible send_mail function that allows you to pass custom Mailgun-specific attributes when sending email including:

  • campaign

  • deliverytime

  • dkim

  • track

  • tracking clicks

  • tracking opens

  • tags

Quick start

  1. Install django_postgun

pip install django_postgun
  1. Add “postgun” to INSTALLED_APPS:

INSTALLED_APPS = (
  ...
  'postgun'
)
  1. Add the following settings to your settings.py:

EMAIL_BACKEND = 'postgun.backends.MailgunEmailBackend'
MAILGUN_DOMAIN = 'example.com'
MAILGUN_API_KEY = 'key-my-api-key'
MAILGUN_PUBLIC_KEY = 'pubkey-my-public-key' #Only needed for email validation

Sending Email

from postman import send_mail
response_data = {}
send_mail('Test Email',  #subject
      'This is your test message.', #text content
      'admin@example.com',  #from address
      ['james@example.com', ],  #recipients
      html_message='This is your <strong>test</strong> message.', #html (optional)
      campaign='test',  #Mailgun campaign id
      tags=['testing', 'august', 'beta'],  #Mailgun tags - 3 max
      reply_to='jacob@example.com', #Reply to address
      response_data=response_data, #Variable to save response data from mailgun i.e. id and message
      )

Getting Email Events

Pull in Mailgun Events for a given period of time and by filter. Accepts all of the regular Mailgun API arguments for events and collects results spread across multiple pages into a single list for processing.

  • begin: datetime The time to start getting events.

  • end: datetime The time to grab events until.

  • ascending: True/False Ascending or descending (defult True)

  • limit: integer Limit to x number of items per page (default 300)

  • field: string Mailgun field filters (default no filter)

import datetime
from postman.events import get_events

begin = datetime.datetime.now() - timedelta(days=1)

items = get_events(begin=begin, limit=100)
for event in items:
  #Process individual JSON events here

Validating Email

Validate email checks against the Mailgun validation API to see if an address is valid.

If an address is invalid and there are no suggestions a ValidationError is raised. If an address is invalid and there are suggestions a ValidationError is raised with the suggestion in the message. Returns True on valid email or ConnectionError, AttributeErrors

from postman.validators import validate_email_mailgun
is_valid = validate_email_mailgun('james@hotmail.co.uk')

Metadata

Release files for django-postgun 0.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-postgun 0.4
File Size Uploaded
django-postgun-0.4.tar.gz 11.1 kB Details

Release files / django-postgun-0.4.tar.gz

Download URL django-postgun-0.4.tar.gz
Size 11.1 kB
Tags Source
SHA-256 checksum
How to use checksums
eb82a1920bae68dff553e06b8b8eb86e059059439e80c06d24b6c82f6cc06ffe
BLAKE2b-256 checksum
How to use checksums
fe0f48ba3fa5ceca1537aa9b2ba2f0a5c34131a1c787e62558af829814e6ca92
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.4 This release

1 release file

0.3

1 release file

0.2

1 release file

0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page