Skip to content

Commit

Permalink
Merge pull request #628 from Marlysson/fix/627
Browse files Browse the repository at this point in the history
Adding support to define custom region in mailgun endpoint.
  • Loading branch information
josephmancuso authored May 17, 2022
2 parents 77381fe + 90fcfe2 commit 6ae58c9
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions .env-example
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ MAIL_PASSWORD=
MAILGUN_REGION=US
MAILGUN_DOMAIN=
MAILGUN_SECRET=
MAIGUN_REGION=us

DB_CONFIG_PATH=tests/integrations/config/database
DB_CONNECTION=sqlite
Expand Down
10 changes: 9 additions & 1 deletion src/masonite/mail/drivers/MailgunDriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,19 @@ def get_attachments(self):

def send(self):
domain = self.options["domain"]
region = self.options.get("region", "us")
secret = self.options["secret"]
attachments = self.get_attachments()

BASE_URL_BY_REGION = {
"us": "https://api.mailgun.net/v3/",
"eu": "https://api.eu.mailgun.net/v3/"
}

endpoint = BASE_URL_BY_REGION.get(region.lower())

return requests.post(
f"https://api.mailgun.net/v3/{domain}/messages",
f"{endpoint}/{domain}/messages",
auth=("api", secret),
data=self.get_mime_message(),
files=attachments,
Expand Down
1 change: 1 addition & 0 deletions tests/integrations/config/mail.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"mailgun": {
"domain": env("MAILGUN_DOMAIN"),
"secret": env("MAILGUN_SECRET"),
"region": env("MAILGUN_REGION"),
"from": FROM_EMAIL,
},
"terminal": {
Expand Down

0 comments on commit 6ae58c9

Please sign in to comment.