Proper exception handling for email send error
This commit is contained in:
parent
982864e1ba
commit
fe7036dae3
2 changed files with 6 additions and 5 deletions
|
@ -41,5 +41,5 @@ def send_notify_mail(request, new_task):
|
||||||
send_mail(
|
send_mail(
|
||||||
email_subject, email_body, new_task.created_by.email,
|
email_subject, email_body, new_task.created_by.email,
|
||||||
[new_task.assigned_to.email], fail_silently=False)
|
[new_task.assigned_to.email], fail_silently=False)
|
||||||
except ConnectionRefusedError:
|
except Exception as e:
|
||||||
messages.error(request, "Task saved but mail not sent. Contact your administrator.")
|
messages.error(request, "Task saved but mail not sent. Contact your administrator.: {}".format(e))
|
||||||
|
|
|
@ -178,15 +178,16 @@ def task_detail(request, task_id):
|
||||||
|
|
||||||
# Get list of all thread participants - everyone who has commented on it plus task creator.
|
# Get list of all thread participants - everyone who has commented on it plus task creator.
|
||||||
commenters = Comment.objects.filter(task=task)
|
commenters = Comment.objects.filter(task=task)
|
||||||
recip_list = [c.author.email for c in commenters]
|
recip_list = [ca.author.email for ca in commenters]
|
||||||
recip_list.append(task.created_by.email)
|
recip_list.append(task.created_by.email)
|
||||||
recip_list = list(set(recip_list)) # Eliminate duplicates
|
recip_list = list(set(recip_list)) # Eliminate duplicates
|
||||||
|
|
||||||
try:
|
try:
|
||||||
send_mail(email_subject, email_body, task.created_by.email, recip_list, fail_silently=False)
|
send_mail(email_subject, email_body, task.created_by.email, recip_list, fail_silently=False)
|
||||||
messages.success(request, "Comment sent to thread participants.")
|
messages.success(request, "Comment sent to thread participants.")
|
||||||
except ConnectionRefusedError:
|
except Exception as e:
|
||||||
messages.error(request, "Comment saved but mail not sent. Contact your administrator.")
|
messages.error(
|
||||||
|
request, "Comment saved but mail not sent. Contact your administrator. :: {}".format(e))
|
||||||
|
|
||||||
messages.success(request, "The task has been edited.")
|
messages.success(request, "The task has been edited.")
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue