Skip to content

Instantly share code, notes, and snippets.

@jehutymax
Created June 3, 2016 12:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jehutymax/752665d992e7acab2f343142191f651d to your computer and use it in GitHub Desktop.
Save jehutymax/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@one.com', 'email@two.com']
for email in recipient_list:
requests.post(
DJANGO_MAILGUN_SERVER_NAME + "/messages",
auth=("api", DJANGO_MAILGUN_API_KEY),
data={"from": "Us <us@email.com>",
"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