Skip to content

Commit

Permalink
Adding multiple email support (#1056)
Browse files Browse the repository at this point in the history
  • Loading branch information
jayasimha-raghavan-unskript authored Apr 30, 2024
1 parent 84b34bc commit de8ea78
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions unskript-ctl/unskript_ctl_notification.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit de8ea78

Please sign in to comment.