11from __future__ import annotations
22
3+ import imaplib
4+ import poplib
35import smtplib
46from email .mime .text import MIMEText
57
@@ -16,10 +18,12 @@ def __init__(self, inputs):
1618 self .body = inputs .get ("body" , "Patchwork Execution Email" )
1719 self .sender_email = inputs ["sender_email" ]
1820 self .recipient_email = inputs ["recipient_email" ]
19- self .password = inputs ["sender_email_password" ]
2021 self .smtp_host = inputs .get ("smtp_host" , "smtp.gmail.com" )
21- self .smtp_port = int (inputs .get ("smtp_port" , 465 ))
22+ self .smtp_username = inputs ["smtp_username" ]
23+ self .smtp_password = inputs ["smtp_password" ]
24+ self .smtp_port = int (inputs .get ("smtp_port" , 25 ))
2225 self .reply_message_id = inputs .get ("reply_message_id" )
26+ self .is_ssl = bool (inputs .get ("is_smtp_ssl" , False ))
2327
2428 def run (self ) -> dict :
2529 msg = MIMEText (mustache_render (self .body , self .email_template_value ))
@@ -30,9 +34,12 @@ def run(self) -> dict:
3034 msg .add_header ("Reference" , self .reply_message_id )
3135 msg .add_header ("In-Reply-To" , self .reply_message_id )
3236
33- # TODO: support smtp without ssl
34- with smtplib .SMTP_SSL (self .smtp_host , self .smtp_port ) as smtp_server :
35- smtp_server .login (self .sender_email , self .password )
36- smtp_server .sendmail (self .sender_email , self .recipient_email , msg .as_string ())
37+ smtp_clazz = smtplib .SMTP
38+ if self .is_ssl :
39+ smtp_clazz = smtplib .SMTP_SSL
40+
41+ with smtp_clazz (host = self .smtp_host , port = self .smtp_port ) as mailserver :
42+ mailserver .login (self .smtp_username , self .smtp_password )
43+ mailserver .sendmail (self .sender_email , self .recipient_email , msg .as_string ())
3744
3845 return dict ()
0 commit comments