From de8ea7847fea4d466c7c279036a7255e3f393c54 Mon Sep 17 00:00:00 2001 From: Jayasimha Raghavan <87547684+jayasimha-raghavan-unskript@users.noreply.github.com> Date: Tue, 30 Apr 2024 07:49:19 -0700 Subject: [PATCH] Adding multiple email support (#1056) --- unskript-ctl/unskript_ctl_notification.py | 24 ++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/unskript-ctl/unskript_ctl_notification.py b/unskript-ctl/unskript_ctl_notification.py index 7364f140c..4b48587ac 100644 --- a/unskript-ctl/unskript_ctl_notification.py +++ b/unskript-ctl/unskript_ctl_notification.py @@ -564,9 +564,15 @@ def send_sendgrid_notification(self, if info_result: html_message += info_result + to_email_list = [] + if isinstance(to_email, list): + to_email_list = to_email + else: + to_email_list = [to_email] + email_message = Mail( from_email=from_email, - to_emails=to_email, + to_emails=to_email_list, subject=email_subject, html_content=html_message ) @@ -694,10 +700,16 @@ def do_send_awsses_email(self, from_email: str, os.environ['AWS_SECRET_ACCESS_KEY'] = secret_key client = boto3.client('ses', region_name=region) + to_email_list = [] + if isinstance(to_email, list): + to_email_list = to_email + else: + to_email_list = [to_email] + try: response = client.send_raw_email( Source=from_email, - Destinations=[to_email], + Destinations=to_email_list, RawMessage={'Data': attachment_.as_string()} ) if response.get('ResponseMetadata') and response.get('ResponseMetadata').get('HTTPStatusCode') == 200: @@ -782,7 +794,13 @@ def send_smtp_notification(self, else: msg['From'] = smtp_user - msg['To'] = to_email + to_email_list = [] + if isinstance(to_email, list): + to_email_list = to_email + else: + to_email_list = [to_email] + + msg['To'] = ", ".join(to_email_list) msg['Subject'] = subject try: server = smtplib.SMTP(smtp_host, self.SMTP_TLS_PORT)