Skip to content

Commit

Permalink
added args extra data for sending email
Browse files Browse the repository at this point in the history
  • Loading branch information
BkrmDahal committed Jul 19, 2019
1 parent be50f98 commit e2bcf7c
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 3 deletions.
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
# constant name <<change these value only>>
PROJECT_NAME = "mailgun"
AUTHOR = "mailgun"
VERSION = "0.1.3"
VERSION = "0.1.4"


# -- General configuration ------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions mailgun/email_parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ def parse_email(email_string: str, email_id: str, output_dir: str = "tmp"):
email_id: ``str``
unique id for email
output_dir: ``str``
folder for attachments
Return:
Email metadata dict: ``dict``
Expand Down
20 changes: 19 additions & 1 deletion mailgun/mailgun.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ def send_message(
html_body: str = None,
text_body: str = None,
files: list = None,
extra_data: dict = None,
):
"""
Send email
Expand All @@ -66,6 +67,8 @@ def send_message(
text_body: ``str``
files: ``list``
list of files
extra_data: ``dict``
extra data for tagging and tracking
Return:
Response from API: ``json``
Expand Down Expand Up @@ -105,6 +108,9 @@ def send_message(
}
data.update(body)

if extra_data:
data.update(extra_data)

# add files
if files:
attachment = []
Expand All @@ -122,7 +128,13 @@ def send_message(
return response.json()

def send_message_template(
self, sender_email: str, to: str, subject: str, template_name: str, data: dict
self,
sender_email: str,
to: str,
subject: str,
template_name: str,
data: dict,
extra_data: dict = None,
):
"""
Send email using template
Expand All @@ -136,6 +148,8 @@ def send_message_template(
template_name: ``str``
data: ``str``
data for template make string from dict using ``json.dumps``
extra_data: ``dict``
extra data for tagging and tracking
Return:
Response from API: ``json``
Expand Down Expand Up @@ -167,6 +181,10 @@ def send_message_template(
"template": template_name,
"h:X-Mailgun-Variables": json.dumps(data),
}

if extra_data:
payload.update(extra_data)

url = self.base_url + "{}/messages".format(self.domain)
response = requests.post(url, auth=self.auth, data=payload)
return response.json()
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setup(
name="mailgun3_python",
version="0.1.3",
version="0.1.4",
description="Mailgun client for python",
long_description=long_description,
long_description_content_type="text/markdown",
Expand Down

0 comments on commit e2bcf7c

Please sign in to comment.