From 1bda3bbff6c28fae4def562f61921aeff34db4e1 Mon Sep 17 00:00:00 2001 From: vindarel Date: Thu, 29 Jul 2021 19:09:04 +0200 Subject: [PATCH 1/2] 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). --- sendgrid/helpers/mail/mail.py | 7 +++++++ test/test_mail_helpers.py | 5 +++++ use_cases/send_a_single_email_to_a_single_recipient.md | 1 + 3 files changed, 13 insertions(+) diff --git a/sendgrid/helpers/mail/mail.py b/sendgrid/helpers/mail/mail.py index ba21f7891..ba04a2b5b 100644 --- a/sendgrid/helpers/mail/mail.py +++ b/sendgrid/helpers/mail/mail.py @@ -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, @@ -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 @@ -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. diff --git a/test/test_mail_helpers.py b/test/test_mail_helpers.py index 57a4ba880..a1cee74c6 100644 --- a/test/test_mail_helpers.py +++ b/test/test_mail_helpers.py @@ -100,6 +100,7 @@ def test_single_email_to_a_single_recipient(self): message = Mail( from_email=From('test+from@example.com', 'Example From Name'), to_emails=To('test+to@example.com', 'Example To Name'), + reply_to=ReplyTo('test+reply_to@example.com', 'Example Reply To Name'), subject=Subject('Sending with SendGrid is Fun'), plain_text_content=PlainTextContent( 'and easy to do anywhere, even with Python'), @@ -123,6 +124,10 @@ def test_single_email_to_a_single_recipient(self): "email": "test+from@example.com", "name": "Example From Name" }, + "reply_to": { + "email": "test+reply_to@example.com", + "name": "Example Reply To Name" + }, "personalizations": [ { "to": [ diff --git a/use_cases/send_a_single_email_to_a_single_recipient.md b/use_cases/send_a_single_email_to_a_single_recipient.md index 8a2364285..c469c3bd6 100644 --- a/use_cases/send_a_single_email_to_a_single_recipient.md +++ b/use_cases/send_a_single_email_to_a_single_recipient.md @@ -6,6 +6,7 @@ from sendgrid.helpers.mail import Mail message = Mail( from_email='from_email@example.com', to_emails='to@example.com', + reply_to='reply_to@example.com', subject='Sending with Twilio SendGrid is Fun', html_content='and easy to do anywhere, even with Python') try: From fd887a63fb9b9c202d98065858dba45d4ac7be9e Mon Sep 17 00:00:00 2001 From: vindarel Date: Thu, 29 Jul 2021 19:36:45 +0200 Subject: [PATCH 2/2] fix: tests: add missing import --- test/test_mail_helpers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_mail_helpers.py b/test/test_mail_helpers.py index a1cee74c6..49c58d05b 100644 --- a/test/test_mail_helpers.py +++ b/test/test_mail_helpers.py @@ -94,7 +94,7 @@ def test_batch_id(self): # Send a Single Email to a Single Recipient def test_single_email_to_a_single_recipient(self): - from sendgrid.helpers.mail import (Mail, From, To, Subject, + from sendgrid.helpers.mail import (Mail, From, To, ReplyTo, Subject, PlainTextContent, HtmlContent) self.maxDiff = None message = Mail(