99
1010
1111class SMTPAlert (BaseAlert ):
12- name = ' smtp'
12+ name = " smtp"
1313
1414 def __init__ (self , host , port , user , password , to ):
1515 self .host = host
@@ -21,11 +21,11 @@ def __init__(self, host, port, user, password, to):
2121 @classmethod
2222 def create_from_env (cls ):
2323 instance = cls (
24- os .environ .get (' EMAIL_HOST' ),
25- os .environ .get (' EMAIL_PORT' ),
26- os .environ .get (' EMAIL_HOST_USER' ),
27- os .environ .get (' EMAIL_HOST_PASSWORD' ),
28- (os .environ .get (' EMAIL_SEND_TO' ) or "" ).split (',' ),
24+ os .environ .get (" EMAIL_HOST" ),
25+ os .environ .get (" EMAIL_PORT" ),
26+ os .environ .get (" EMAIL_HOST_USER" ),
27+ os .environ .get (" EMAIL_HOST_PASSWORD" ),
28+ (os .environ .get (" EMAIL_SEND_TO" ) or "" ).split ("," ),
2929 )
3030 if instance .properly_configured :
3131 return instance
@@ -36,11 +36,11 @@ def create_from_env(cls):
3636 def properly_configured (self ) -> bool :
3737 return self .host and self .port and self .user and len (self .to ) > 0
3838
39- def send (self , subject : str = None , body : str = None , alert_type : str = ' INFO' ):
39+ def send (self , subject : str = None , body : str = None , alert_type : str = " INFO" ):
4040 msg = MIMEText (body )
41- msg [' Subject' ] = f"[{ alert_type } ] { subject } "
42- msg [' From' ] = self .user
43- msg ['To' ] = ', ' .join (self .to )
41+ msg [" Subject" ] = f"[{ alert_type } ] { subject } "
42+ msg [" From" ] = self .user
43+ msg ["To" ] = ", " .join (self .to )
4444
4545 try :
4646 logger .info ("Connecting to %s port %s" , self .host , self .port )
@@ -52,15 +52,17 @@ def send(self, subject: str = None, body: str = None, alert_type: str = 'INFO'):
5252 try :
5353 server .starttls ()
5454 except smtplib .SMTPHeloError :
55- logger .error ("The server didn't reply properly to the HELO greeting. Email not sent." )
55+ logger .error (
56+ "The server didn't reply properly to the HELO greeting. Email not sent."
57+ )
5658 return
5759 except smtplib .SMTPNotSupportedError :
5860 logger .error ("STARTTLS not supported on server. Email not sent." )
5961 return
6062 server .ehlo ()
6163 server .login (self .user , self .password )
6264 server .sendmail (self .user , self .to , msg .as_string ())
63- logger .info (' Email sent' )
65+ logger .info (" Email sent" )
6466 except Exception as ex :
6567 logger .exception (ex )
6668 finally :
0 commit comments