Skip to content

Commit

Permalink
Adds reply_to_list (#121)
Browse files Browse the repository at this point in the history
  • Loading branch information
sklarsa committed Nov 9, 2023
1 parent 1ced2eb commit 00da6d8
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
1 change: 0 additions & 1 deletion dev-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 7 additions & 0 deletions sendgrid_backend/mail.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
25 changes: 25 additions & 0 deletions test/test_mail.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 <sam.smith@example.com>",
to=["John Doe <john.doe@example.com>", "jane.doe@example.com"],
cc=["Stephanie Smith <stephanie.smith@example.com>"],
bcc=["Sarah Smith <sarah.smith@example.com>"],
)

msg.reply_to_list = ["John Doe <john.doe@example.com>", "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")

0 comments on commit 00da6d8

Please sign in to comment.