Skip to content

Instantly share code, notes, and snippets.

@PandaWhoCodes
Forked from jehutymax/python-mailgun.py
Created January 2, 2018 16:52
Show Gist options
  • Save PandaWhoCodes/c1225edf67eec5f50b7cac07600ea9f1 to your computer and use it in GitHub Desktop.
Save PandaWhoCodes/c1225edf67eec5f50b7cac07600ea9f1 to your computer and use it in GitHub Desktop.
Send e-mails using Mailgun from a Python script
import string
import requests
html = 'https://s3.amazonaws.com/.../email.htm'
content = requests.get(html)
DJANGO_MAILGUN_SERVER_NAME = ''
DJANGO_MAILGUN_API_KEY = ''
recipient_list = ['[email protected]', '[email protected]']
for email in recipient_list:
requests.post(
DJANGO_MAILGUN_SERVER_NAME + "/messages",
auth=("api", DJANGO_MAILGUN_API_KEY),
data={"from": "Us <[email protected]>",
"to": email,
"o:campaign": "", # optional, but it was cool (and creepy) to track opens and clicks.
"subject": "Your subject",
"text": 'Your alt text for non-html clients',
"html": content.text})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment