Skip to content

Commit

Permalink
Add reply_to to helpers.Mail
Browse files Browse the repository at this point in the history
Otherwise, we must create the Mail and then set the reply_to thanks to
its setter.
(and we have to dig the code to find out).
  • Loading branch information
vindarel committed Jul 29, 2021
1 parent c905e05 commit 9f1af08
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
7 changes: 7 additions & 0 deletions sendgrid/helpers/mail/mail.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def __init__(
self,
from_email=None,
to_emails=None,
reply_to=None,
subject=None,
plain_text_content=None,
html_content=None,
Expand All @@ -40,6 +41,8 @@ def __init__(
:param to_emails: The email address of the recipient
:type to_emails: To, str, tuple, list(str), list(tuple),
list(To), optional
:param reply_to: The email address to reply to
:type reply_to: ReplyTo, tuple, optional
:param plain_text_content: The plain text body of the email
:type plain_text_content: string, optional
:param html_content: The html body of the email
Expand Down Expand Up @@ -79,6 +82,10 @@ def __init__(
if html_content is not None:
self.add_content(html_content, MimeType.html)

# Optional
if reply_to is not None:
self.reply_to = reply_to

def __str__(self):
"""A JSON-ready string representation of this Mail object.
Expand Down
5 changes: 5 additions & 0 deletions test/test_mail_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ def test_single_email_to_a_single_recipient(self):
message = Mail(
from_email=From('[email protected]', 'Example From Name'),
to_emails=To('[email protected]', 'Example To Name'),
reply_to=ReplyTo('[email protected]', 'Example Reply To Name'),
subject=Subject('Sending with SendGrid is Fun'),
plain_text_content=PlainTextContent(
'and easy to do anywhere, even with Python'),
Expand All @@ -123,6 +124,10 @@ def test_single_email_to_a_single_recipient(self):
"email": "[email protected]",
"name": "Example From Name"
},
"reply_to": {
"email": "[email protected]",
"name": "Example Reply To Name"
},
"personalizations": [
{
"to": [
Expand Down

0 comments on commit 9f1af08

Please sign in to comment.