11from __future__ import annotations
22
33import smtplib
4- from email .mime . text import MIMEText
4+ from email .message import EmailMessage
55
66from patchwork .common .utils .input_parsing import parse_to_list
77from patchwork .common .utils .utils import mustache_render
@@ -25,10 +25,11 @@ def __init__(self, inputs):
2525 self .is_ssl = bool (inputs .get ("is_smtp_ssl" , False ))
2626
2727 def run (self ) -> dict :
28- 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 ))
2930 msg ["Subject" ] = mustache_render (self .subject , self .email_template_value )
3031 msg ["From" ] = self .sender_email
31- msg ["To" ] = "," .join (self .recipient_email )
32+ msg ["To" ] = ", " .join (self .recipient_email )
3233 if self .reply_message_id is not None :
3334 msg .add_header ("Reference" , self .reply_message_id )
3435 msg .add_header ("In-Reply-To" , self .reply_message_id )
@@ -39,6 +40,5 @@ def run(self) -> dict:
3940
4041 with smtp_clazz (host = self .smtp_host , port = self .smtp_port ) as mailserver :
4142 mailserver .login (self .smtp_username , self .smtp_password )
42- mailserver .sendmail (self .sender_email , self .recipient_email , msg .as_string ())
43-
43+ mailserver .send_message (msg )
4444 return dict ()
0 commit comments