Skip to content

Instantly share code, notes, and snippets.

@masiamj
Last active May 21, 2018 17:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save masiamj/1e497d900fdfb70795ffd828775edea9 to your computer and use it in GitHub Desktop.
Save masiamj/1e497d900fdfb70795ffd828775edea9 to your computer and use it in GitHub Desktop.
Example Python code for Mike
import sys
import requests
"""Define Constants"""
MAILGUN_DOMAIN = ""
MAILGUN_API_KEY = ""
'''
Entry point for the application
'''
def main():
email_recipients = ["test@email.com"]
try:
response = send_simple_message("This is the subject", "This is the body", email_recipients)
response.raise_for_status()
print(f"Sent summary email successfully to {', '.join(email_recipients)}")
except requests.exceptions.HTTPError as error:
return "Error Running Script: " + str(error)
finally:
print("Done Running Script!")
'''
Sends an email via Mailgun
param {string} subject - Subject of the email
param {string} text - Body of the email
param {List<string>} to - List of emails
'''
def send_simple_message(subject, text, to):
return requests.post(
f"https://api.mailgun.net/v3/{MAILGUN_DOMAIN}/messages",
auth=("api", MAILGUN_API_KEY),
data={
"from": "Other User <user@email.com>",
"to": to,
"subject": subject,
"text": text
}
)
'''
Parse CSV file
param {string} file_name
'''
def parse_csv(file_name):
pass
'''
Creates a message about a row
'''
def create_message(row):
pass
"""Executor"""
if __name__ == '__main__':
sys.exit(main())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment