Commit caca04b6 authored by Malcolm's avatar Malcolm

Allow use of eu sparkpost account

parent c535395c
Pipeline #67888767 passed with stage
in 2 minutes and 11 seconds
......@@ -100,7 +100,10 @@ def _can_use_smtp():
def _can_use_sparkpost():
api_key = None
result = False
if "SparkPostEmailBackend" in settings.EMAIL_BACKEND:
if (
"SparkPostEmailBackend" in settings.EMAIL_BACKEND or
"sparkpost.EmailBackend" in settings.EMAIL_BACKEND
):
try:
api_key = settings.SPARKPOST_API_KEY
result = api_key
......@@ -197,7 +200,7 @@ def _mail_send(m):
e_msg = e.message
else:
e_msg = e
logger.error("{} ({}): {}".format(m.message, m.pk, e_msg))
logger.error("{} ({}): {} {}".format(m.message, m.pk, e_msg, e))
retry_count = m.retry_count or 0
m.retry_count = retry_count + 1
m.save()
......@@ -230,6 +233,7 @@ def _send_mail_simple(m):
)
for attachment in m.message.attachments():
email.attach_file(attachment.document.file.name)
print (email)
email.send(fail_silently=False)
return True
......@@ -338,7 +342,16 @@ def _send_mail_sparkpost_template(m):
accepted = rejected = 0
try:
sp = SparkPost()
if (
hasattr(settings, "ANYMAIL") and
hasattr(settings.ANYMAIL, "SPARKPOST_API_URL")
):
sp = SparkPost(
settings.SPARKPOST_API_KEY,
settings.ANYMAIL["SPARKPOST_API_URL"]
)
else:
sp = SparkPost()
user_vars = _get_merge_vars(m)
resp = sp.transmissions.send(
recipients=email_addresses,
......@@ -399,13 +412,17 @@ def _using_mandrill():
def _using_sparkpost():
"""We are using sparkpost... so check settings."""
if "SparkPostEmailBackend" not in settings.EMAIL_BACKEND:
if (
"SparkPostEmailBackend" in settings.EMAIL_BACKEND or
"sparkpost.EmailBackend" in settings.EMAIL_BACKEND
):
if not _can_use_sparkpost():
raise MailError("The Sparkpost API key is not configured")
else:
raise MailError(
"The email backend is not 'SparkPostEmailBackend'. You cannot "
"send messages using Sparkpost (or send Sparkpost templates)."
)
if not _can_use_sparkpost():
raise MailError("The Sparkpost API key is not configured")
def get_mail_template(slug):
......
......@@ -4,10 +4,10 @@ django-braces==1.13.0
django-redis==4.9.1
django-reversion==3.0.3
django-sendfile==0.3.11
Django==2.1.7
Django==2.2.2
djrill==2.1.0
psycopg2==2.7.7 --no-binary=psycopg2
python-dateutil==2.7.5
pytz==2018.9
psycopg2==2.8.1
python-dateutil==2.8.0
pytz==2019.1
redis==2.10.6
sparkpost==1.3.6
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