Skip to content

Commit 272274a

Browse files
feat: add reply_to to helpers.Mail (#999)
* Add reply_to to helpers.Mail 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). * fix: tests: add missing import Co-authored-by: Jennifer Mah <[email protected]>
1 parent 4047acd commit 272274a

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

sendgrid/helpers/mail/mail.py

+7
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ def __init__(
2424
self,
2525
from_email=None,
2626
to_emails=None,
27+
reply_to=None,
2728
subject=None,
2829
plain_text_content=None,
2930
html_content=None,
@@ -40,6 +41,8 @@ def __init__(
4041
:param to_emails: The email address of the recipient
4142
:type to_emails: To, str, tuple, list(str), list(tuple),
4243
list(To), optional
44+
:param reply_to: The email address to reply to
45+
:type reply_to: ReplyTo, tuple, optional
4346
:param plain_text_content: The plain text body of the email
4447
:type plain_text_content: string, optional
4548
:param html_content: The html body of the email
@@ -79,6 +82,10 @@ def __init__(
7982
if html_content is not None:
8083
self.add_content(html_content, MimeType.html)
8184

85+
# Optional
86+
if reply_to is not None:
87+
self.reply_to = reply_to
88+
8289
def __str__(self):
8390
"""A JSON-ready string representation of this Mail object.
8491

test/test_mail_helpers.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,13 @@ def test_batch_id(self):
9494

9595
# Send a Single Email to a Single Recipient
9696
def test_single_email_to_a_single_recipient(self):
97-
from sendgrid.helpers.mail import (Mail, From, To, Subject,
97+
from sendgrid.helpers.mail import (Mail, From, To, ReplyTo, Subject,
9898
PlainTextContent, HtmlContent)
9999
self.maxDiff = None
100100
message = Mail(
101101
from_email=From('[email protected]', 'Example From Name'),
102102
to_emails=To('[email protected]', 'Example To Name'),
103+
reply_to=ReplyTo('[email protected]', 'Example Reply To Name'),
103104
subject=Subject('Sending with SendGrid is Fun'),
104105
plain_text_content=PlainTextContent(
105106
'and easy to do anywhere, even with Python'),
@@ -123,6 +124,10 @@ def test_single_email_to_a_single_recipient(self):
123124
"email": "[email protected]",
124125
"name": "Example From Name"
125126
},
127+
"reply_to": {
128+
"email": "[email protected]",
129+
"name": "Example Reply To Name"
130+
},
126131
"personalizations": [
127132
{
128133
"to": [

use_cases/send_a_single_email_to_a_single_recipient.md

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ from sendgrid.helpers.mail import Mail
66
message = Mail(
77
from_email='[email protected]',
88
to_emails='[email protected]',
9+
reply_to='[email protected]',
910
subject='Sending with Twilio SendGrid is Fun',
1011
html_content='<strong>and easy to do anywhere, even with Python</strong>')
1112
try:

0 commit comments

Comments
 (0)