Skip to content

Commit cec34cb

Browse files
committed
Add POSTMARK_TRACK_CHANGES setting to core and Django backend
1 parent e556658 commit cec34cb

4 files changed

Lines changed: 21 additions & 3 deletions

File tree

CONTRIBUTORS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,6 @@ Everyone that made python-postmark awesome
1515
- James Arthur (http://github.com/thruflo)
1616
- Jacob (http://github.com/nephics)
1717
- Josh Owen (https://github.com/joshowen)
18+
- Daniel Shapiro (https://github.com/danxshap)
1819

1920
(Did I miss anyone?)

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,10 @@ Django
4242
The library can be used stand-alone with Django. You can also add the settings:
4343

4444
```python
45-
POSTMARK_API_KEY = 'your-key'
46-
POSTMARK_SENDER = '[email protected]'
47-
POSTMARK_TEST_MODE = [True/False]
45+
POSTMARK_API_KEY = 'your-key'
46+
POSTMARK_SENDER = '[email protected]'
47+
POSTMARK_TEST_MODE = [True/False]
48+
POSTMARK_TRACK_OPENS = [True/False]
4849
```
4950

5051
to your settings.py file, and when you create a new PMMail object, it will grab the API key and sender automatically. Make sure the sender email address is one of your Sender Signature email addresses in Postmark. You can also customize the name on the sender by changing the format from '[email protected]' to 'Sender Name <[email protected]>' as long as the email part is part of a Sender Signature in Postmark.

postmark/core.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,8 @@ def __init__(self, **kwargs):
136136
self.__api_key = django_settings.POSTMARK_API_KEY
137137
if not self.__sender and hasattr(django_settings, 'POSTMARK_SENDER'):
138138
self.__sender = django_settings.POSTMARK_SENDER
139+
if not self.__track_opens and hasattr(django_settings, 'POSTMARK_TRACK_OPENS'):
140+
self.__track_opens = django_settings.POSTMARK_TRACK_OPENS
139141
except ImportError:
140142
pass
141143

postmark/django_backend.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ def __init__(self, *args, **kwargs):
1313
else:
1414
self.tag = None
1515

16+
if 'track_opens' in kwargs:
17+
self.track_opens = kwargs['track_opens']
18+
del kwargs['track_opens']
19+
else:
20+
self.track_opens = getattr(settings, 'POSTMARK_TRACK_OPENS', False)
21+
1622
super(PMEmailMessage, self).__init__(*args, **kwargs)
1723

1824
class PMEmailMultiAlternatives(EmailMultiAlternatives):
@@ -23,6 +29,12 @@ def __init__(self, *args, **kwargs):
2329
else:
2430
self.tag = None
2531

32+
if 'track_opens' in kwargs:
33+
self.track_opens = kwargs['track_opens']
34+
del kwargs['track_opens']
35+
else:
36+
self.track_opens = getattr(settings, 'POSTMARK_TRACK_OPENS', False)
37+
2638
super(PMEmailMultiAlternatives, self).__init__(*args, **kwargs)
2739

2840
class EmailBackend(BaseEmailBackend):
@@ -92,6 +104,8 @@ def _build_message(self, message):
92104
attachments=attachments)
93105

94106
postmark_message.tag = getattr(message, 'tag', None)
107+
postmark_message.track_opens = getattr(message, 'track_opens', False)
108+
95109
return postmark_message
96110

97111
def _send(self, messages):

0 commit comments

Comments
 (0)