Skip to content

Commit

Permalink
Log when not all emails could be sent
Browse files Browse the repository at this point in the history
  • Loading branch information
hmpf committed Apr 17, 2024
1 parent 6a951c6 commit a3d4c3a
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/argus/notificationprofile/media/email.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def modelinstance_to_dict(obj):
return dict_


def send_email_safely(function, additional_error=None, *args, **kwargs):
def send_email_safely(function, additional_error=None, *args, **kwargs) -> int:
try:
result = function(*args, **kwargs)
return result
Expand Down Expand Up @@ -183,17 +183,25 @@ def send(cls, event: Event, destinations: Iterable[DestinationConfig], **_) -> b
email_addresses = cls.get_relevant_addresses(destinations=destinations)
if not email_addresses:
return False
num_emails = len(email_addresses)

subject, message, html_message = cls.create_message_context(event=event)

failed = set()
for email_address in email_addresses:
send_email_safely(
sent = send_email_safely(
send_mail,
subject=subject,
message=message,
from_email=None,
recipient_list=[email_address],
html_message=html_message,
)
if not sent: # 0 for failure otherwise 1
failed.add(email_address)

if failed:
LOG.warn("Email: Failed to send to %i addresses", len(failed))
LOG.debug("Email: Failed to send to:", " ".join(failed))
return False
return True

0 comments on commit a3d4c3a

Please sign in to comment.