Skip to content

Commit

Permalink
Merge pull request #38 from MoBagel/chore/mailgun-retry
Browse files Browse the repository at this point in the history
add retry for mailgun request
  • Loading branch information
yingtung committed Feb 21, 2023
2 parents 37ccdec + 042dee1 commit e041e64
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions awesome_sso/mail/mailgun.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

import requests
from pydantic import EmailStr, HttpUrl
from requests.adapters import HTTPAdapter
from urllib3.util.retry import Retry


class MailGun:
Expand All @@ -25,7 +27,12 @@ def send_simple_message(
cc: List[EmailStr] = [],
bcc: List[EmailStr] = [],
):
return requests.post(
session = requests.Session()
retry = Retry(connect=3, backoff_factor=0.5)
adapter = HTTPAdapter(max_retries=retry)
session.mount("http://", adapter)
session.mount("https://", adapter)
return session.post(
self.base_url + "/messages",
auth=("api", self.api_key),
files=[("attachment", attachment) for attachment in attachments],
Expand All @@ -51,7 +58,13 @@ def send_template(
cc: List[EmailStr] = [],
bcc: List[EmailStr] = [],
):
return requests.post(

session = requests.Session()
retry = Retry(connect=3, backoff_factor=0.5)
adapter = HTTPAdapter(max_retries=retry)
session.mount("http://", adapter)
session.mount("https://", adapter)
return session.post(
self.base_url + "/messages",
auth=("api", self.api_key),
files=[("attachment", attachment) for attachment in attachments],
Expand Down

0 comments on commit e041e64

Please sign in to comment.