11from __future__ import annotations
22
33import smtplib
4- from email .mime . text import MIMEText
4+ from email .message import EmailMessage
55
6+ from patchwork .common .utils .input_parsing import parse_to_list
67from patchwork .common .utils .utils import mustache_render
78from patchwork .step import Step
89from patchwork .steps .SendEmail .typed import SendEmailInputs , SendEmailOutputs
@@ -15,7 +16,7 @@ def __init__(self, inputs):
1516 self .subject = inputs .get ("subject" , "Patchwork Execution Email" )
1617 self .body = inputs .get ("body" , "Patchwork Execution Email" )
1718 self .sender_email = inputs ["sender_email" ]
18- self .recipient_email = inputs ["recipient_email" ]
19+ self .recipient_email = parse_to_list ( inputs ["recipient_email" ], [ " " , "," ])
1920 self .smtp_host = inputs .get ("smtp_host" , "smtp.gmail.com" )
2021 self .smtp_username = inputs ["smtp_username" ]
2122 self .smtp_password = inputs ["smtp_password" ]
@@ -24,10 +25,11 @@ def __init__(self, inputs):
2425 self .is_ssl = bool (inputs .get ("is_smtp_ssl" , False ))
2526
2627 def run (self ) -> dict :
27- msg = MIMEText (mustache_render (self .body , self .email_template_value ))
28+ msg = EmailMessage ()
29+ msg .set_content (mustache_render (self .body , self .email_template_value ))
2830 msg ["Subject" ] = mustache_render (self .subject , self .email_template_value )
2931 msg ["From" ] = self .sender_email
30- msg ["To" ] = self .recipient_email
32+ msg ["To" ] = ", " . join ( self .recipient_email )
3133 if self .reply_message_id is not None :
3234 msg .add_header ("Reference" , self .reply_message_id )
3335 msg .add_header ("In-Reply-To" , self .reply_message_id )
@@ -38,6 +40,5 @@ def run(self) -> dict:
3840
3941 with smtp_clazz (host = self .smtp_host , port = self .smtp_port ) as mailserver :
4042 mailserver .login (self .smtp_username , self .smtp_password )
41- mailserver .sendmail (self .sender_email , self .recipient_email , msg .as_string ())
42-
43+ mailserver .send_message (msg )
4344 return dict ()
0 commit comments