Skip to content

Support using Mailgun's EU region #28

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
@@ -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.
@@ -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"] ),
5 changes: 5 additions & 0 deletions generate_config.py
Original file line number Diff line number Diff line change
@@ -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: ")