From 00da6d8ae1e1ea77dd3000dd5f096f02d61cf9a4 Mon Sep 17 00:00:00 2001 From: Steven Sklar Date: Wed, 8 Nov 2023 20:09:25 -0500 Subject: [PATCH] Adds reply_to_list (#121) --- dev-requirements.txt | 1 - sendgrid_backend/mail.py | 7 +++++++ test/test_mail.py | 25 +++++++++++++++++++++++++ 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/dev-requirements.txt b/dev-requirements.txt index 3c341bc..56e4923 100644 --- a/dev-requirements.txt +++ b/dev-requirements.txt @@ -10,5 +10,4 @@ pytest==6.2.5 pytest-cov==3.0.0 tox==3.8.5 twine==3.3.0 -typed-ast==1.5.1 wheel diff --git a/sendgrid_backend/mail.py b/sendgrid_backend/mail.py index dd63787..6e6afb7 100644 --- a/sendgrid_backend/mail.py +++ b/sendgrid_backend/mail.py @@ -471,6 +471,13 @@ def _build_sg_mail(self, msg: EmailMessage) -> Dict: ) ) + if hasattr(msg, "reply_to_list") and SENDGRID_6: + from sendgrid.helpers.mail import ReplyTo + + mail.reply_to_list = [ + ReplyTo(*self._parse_email_address(e)) for e in msg.reply_to_list + ] + if hasattr(msg, "categories"): for cat in msg.categories: mail.add_category(Category(cat)) diff --git a/test/test_mail.py b/test/test_mail.py index 55ede5e..bb7862a 100644 --- a/test/test_mail.py +++ b/test/test_mail.py @@ -727,3 +727,28 @@ def test_tracking_config(self): assert not tracking_settings["click_tracking"]["enable"] assert "ganalytics" in tracking_settings assert tracking_settings["ganalytics"]["utm_source"] == "my-source" + + def test_reply_to_list(self): + msg = EmailMessage( + subject="Hello, World!", + body="Hello, World!", + from_email="Sam Smith ", + to=["John Doe ", "jane.doe@example.com"], + cc=["Stephanie Smith "], + bcc=["Sarah Smith "], + ) + + msg.reply_to_list = ["John Doe ", "jane.doe@example.com"] + + mail = self.backend._build_sg_mail(msg) + + reply_to_list = mail.get("reply_to_list") + if SENDGRID_5: + assert not reply_to_list + else: + assert reply_to_list + assert len(reply_to_list) == 2 + assert reply_to_list[0].get("email") == "john.doe@example.com" + assert reply_to_list[0].get("name") == "John Doe" + assert reply_to_list[1].get("email") == "jane.doe@example.com" + assert not reply_to_list[1].get("name")