diff --git a/api/apiserver.py b/api/apiserver.py
index 336c09f..c9032e8 100755
--- a/api/apiserver.py
+++ b/api/apiserver.py
@@ -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 += "
" # I'm so sorry.
@@ -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"] ),
diff --git a/generate_config.py b/generate_config.py
index 2af17d7..e2e8349 100755
--- a/generate_config.py
+++ b/generate_config.py
@@ -94,6 +94,7 @@
settings = {
"email_from":"",
+ "mailgun_api_region":"",
"mailgun_api_key":"",
"mailgun_sending_domain":"",
"domain": "",
@@ -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: ")