Skip to content

Commit cf992c3

Browse files
committed
Postmark: handle Reply-To in EmailMessage headers
Move 'Reply-To' header into dedicated Postmark API param Fixes #39 (cherry picked from commit 4ca39a9)
1 parent d1600bf commit cf992c3

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

anymail/backends/postmark.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import re
22

3+
from requests.structures import CaseInsensitiveDict
4+
35
from ..exceptions import AnymailRequestsAPIError
46
from ..message import AnymailRecipientStatus
57
from ..utils import get_anymail_setting
@@ -140,9 +142,12 @@ def set_reply_to(self, emails):
140142
self.data["ReplyTo"] = reply_to
141143

142144
def set_extra_headers(self, headers):
145+
header_dict = CaseInsensitiveDict(headers)
146+
if 'Reply-To' in header_dict:
147+
self.data["ReplyTo"] = header_dict.pop('Reply-To')
143148
self.data["Headers"] = [
144149
{"Name": key, "Value": value}
145-
for key, value in headers.items()
150+
for key, value in header_dict.items()
146151
]
147152

148153
def set_text_body(self, body):

tests/test_postmark_backend.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,9 @@ def test_email_message(self):
8585
self.assertEqual(data['To'], '[email protected], Also To <[email protected]>')
8686
self.assertEqual(data['Bcc'], '[email protected], Also BCC <[email protected]>')
8787
self.assertEqual(data['Cc'], '[email protected], Also CC <[email protected]>')
88+
self.assertEqual(data['ReplyTo'], '[email protected]')
8889
self.assertCountEqual(data['Headers'], [
8990
{'Name': 'Message-ID', 'Value': '[email protected]'},
90-
{'Name': 'Reply-To', 'Value': '[email protected]'},
9191
{'Name': 'X-MyHeader', 'Value': 'my value'},
9292
])
9393

@@ -136,6 +136,16 @@ def test_reply_to(self):
136136
self.assertEqual(data['ReplyTo'], '[email protected], Other <[email protected]>')
137137
self.assertEqual(data['Headers'], [{'Name': 'X-Other', 'Value': 'Keep'}]) # don't lose other headers
138138

139+
def test_reply_to_header(self):
140+
# Reply-To needs to be moved out of headers, into dedicated param
141+
email = mail.EmailMessage('Subject', 'Body goes here', '[email protected]', ['[email protected]'],
142+
headers={'reply-to': '[email protected], Other <[email protected]>',
143+
'X-Other': 'Keep'})
144+
email.send()
145+
data = self.get_api_call_json()
146+
self.assertEqual(data['ReplyTo'], '[email protected], Other <[email protected]>')
147+
self.assertEqual(data['Headers'], [{'Name': 'X-Other', 'Value': 'Keep'}]) # don't lose other headers
148+
139149
def test_attachments(self):
140150
text_content = "* Item one\n* Item two\n* Item three"
141151
self.message.attach(filename="test.txt", content=text_content, mimetype="text/plain")

0 commit comments

Comments
 (0)