Commit ada579bc authored by Malcolm's avatar Malcolm

Use Sparkpost track options with anymail

parent 5690ee1a
Pipeline #67935579 passed with stage
in 1 minute and 50 seconds
......@@ -233,6 +233,11 @@ def _send_mail_simple(m):
)
for attachment in m.message.attachments():
email.attach_file(attachment.document.file.name)
# if using anymail and sparkpost set track options
if hasattr(settings, "ANYMAIL") and hasattr(settings, "SPARKPOST_OPTIONS"):
email.track_opens, email.track_clicks = _get_sparkpost_track_options()
email.send(fail_silently=False)
return True
......@@ -312,6 +317,21 @@ def _send_mail_mandrill_template(m):
return result
def _get_sparkpost_track_options():
try:
# Allow track_opens to be set to on per project basis
track_opens = settings.SPARKPOST_OPTIONS.get("track_opens", True)
except AttributeError:
track_opens = True
try:
# Allow track_clicks to be set to on per project basis
track_clicks = settings.SPARKPOST_OPTIONS.get("track_clicks", False)
except AttributeError:
track_clicks = False
return track_opens, track_clicks
def _send_mail_sparkpost_template(m):
"""Send message to a single email address.
......@@ -328,16 +348,7 @@ def _send_mail_sparkpost_template(m):
email_addresses = [m.email]
try:
# Allow track_opens to be set to on per project basis
track_opens = settings.SPARKPOST_OPTIONS.get("track_opens", True)
except AttributeError:
track_opens = True
try:
# Allow track_clicks to be set to on per project basis
track_clicks = settings.SPARKPOST_OPTIONS.get("track_clicks", False)
except AttributeError:
track_clicks = False
track_opens, track_clicks = _get_sparkpost_track_options()
accepted = rejected = 0
try:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment