Add error handling to send_mail

This commit is contained in:
Jan Tuomi
2017-10-30 12:49:30 +02:00
parent b09698e859
commit 06cb73b5b4
+12 -9
View File
@@ -23,16 +23,19 @@ from django.core.mail import send_mail
def send_email(to, subject, body):
success = send_mail(
subject,
body,
settings.DEFAULT_EMAIL_FROM,
[to],
fail_silently=False,
)
try:
success = send_mail(
subject,
body,
settings.DEFAULT_EMAIL_FROM,
[to],
fail_silently=False,
)
if success == 0:
raise Exception('Failed to send email!')
if success == 0:
raise Exception('Failed to send email!')
except Exception as ex:
logging.exception('Failed to send email.')
@require_http_methods(["GET"])