Skip to content

Instantly share code, notes, and snippets.

@campos-rafael
Created June 3, 2016 12:30
Show Gist options
  • Save campos-rafael/752665d992e7acab2f343142191f651d to your computer and use it in GitHub Desktop.
Save campos-rafael/752665d992e7acab2f343142191f651d 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})
@WillWang2122
Copy link

Thank you so much for the code. 🫡🫡🫡🫡🫡🫡

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment