Skip to content

Commit 686b257

Browse files
committed
fix(email): Skip for empty email on notification
1 parent 111774e commit 686b257

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

notifications/notification.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ def construct_msg(cc_addresses, subject, html):
7373
return msg
7474

7575

76+
def clean_emails(emails):
77+
return [e for e in emails if isinstance(e, str) and e.strip()]
78+
79+
7680
def send_notification(subject, recipients, html, mailtype="", cc_recipients=None, files=None):
7781
"""Generic email sending method, handly only HTML emails currently"""
7882
cc_recipients = cc_recipients or []
@@ -84,10 +88,14 @@ def send_notification(subject, recipients, html, mailtype="", cc_recipients=None
8488
print("-" * 22, "EMAIL END -", "-" * 22)
8589
return
8690

87-
to_addresses = recipients if isinstance(recipients, list) else [recipients]
88-
cc_addresses = cc_recipients if isinstance(cc_recipients, list) else [cc_recipients]
91+
to_addresses = clean_emails(recipients)
92+
cc_addresses = clean_emails(cc_recipients)
8993
addresses = to_addresses + cc_addresses
9094

95+
if not addresses:
96+
logger.info("No valid email addresses provided for sending the notification.")
97+
return
98+
9199
if settings.DEBUG_EMAIL:
92100
print("-" * 22, "EMAIL START", "-" * 22)
93101
print(f"\n{html}\n")

0 commit comments

Comments
 (0)