Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion api/apiserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,12 @@ def record_callback_in_database( callback_data, request_handler ):
def email_sent_callback( response ):
print response.body

def mailgun_api_url( region ):
if region.lower() == "eu":
return "https://api.eu.mailgun.net/v3/"
else:
return "https://api.mailgun.net/v3/"

def send_email( to, subject, body, attachment_file, body_type="html" ):
if body_type == "html":
body += "<br /><img src=\"https://api." + settings["domain"] + "/" + attachment_file.encode( "utf-8" ) + "\" />" # I'm so sorry.
Expand All @@ -241,7 +247,7 @@ def send_email( to, subject, body, attachment_file, body_type="html" ):
body_type: urllib.quote_plus( body ),
}

thread = unirest.post( "https://api.mailgun.net/v3/" + settings["mailgun_sending_domain"] + "/messages",
thread = unirest.post( mailgun_api_url( settings["mailgun_api_region"] ) + settings["mailgun_sending_domain"] + "/messages",
headers={"Accept": "application/json"},
params=email_data,
auth=("api", settings["mailgun_api_key"] ),
Expand Down
5 changes: 5 additions & 0 deletions generate_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@

settings = {
"email_from":"",
"mailgun_api_region":"",
"mailgun_api_key":"",
"mailgun_sending_domain":"",
"domain": "",
Expand Down Expand Up @@ -126,6 +127,10 @@
print "(ex. key-8da843ff65205a61374b09b81ed0fa35)"
settings["mailgun_api_key"] = raw_input( "Mailgun API key: ")
print ""
print "What is your Mailgun region? "
print "(ex. US or EU)"
settings["mailgun_api_region"] = raw_input( "Mailgun region: ")
print ""
print "What is your Mailgun domain? "
print "(ex. example.com)"
settings["mailgun_sending_domain"] = raw_input( "Mailgun domain: ")
Expand Down