2323import smtplib
2424import logging
2525
26- from email .mime .application import MIMEApplication
2726from email .mime .multipart import MIMEMultipart
2827from email .mime .text import MIMEText
29- from typing import List
3028
3129logger = logging .getLogger (__name__ )
3230
33- class EmailSender :
3431
35- def __init__ (self , recipient_email : List [str ] = None ):
32+ class EmailSender :
33+ def __init__ (self , recipient_email = None ):
34+ if recipient_email is None :
35+ recipient_email = []
3636 self .recipient_email = recipient_email
3737 self .mime_msg = MIMEMultipart ()
3838 self .send_from = ""
39- self .send_to = ""
39+ self .send_to = [ "" ]
4040
4141 def create_email_msg (self , subject_msg : str ):
4242 if not self .recipient_email :
@@ -50,14 +50,17 @@ def create_email_msg(self, subject_msg: str):
5050 self .mime_msg ["To" ] = ", " .join (self .send_to )
5151 self .mime_msg ["Subject" ] = subject_msg
5252
53- def send_email (self , subject_msg , body : List [str ] = None ):
53+ def send_email (self , subject_msg , body = None ):
54+ if body is None :
55+ body = []
5456 whole_body = "" .join (body )
55- msg = ("<html><head><style>table, th, td {border: 1px solid black;}</style></head>"
56- f"<body>{ whole_body } </body></html>" )
57+ msg = (
58+ "<html><head><style>table, th, td {border: 1px solid black;}</style></head>"
59+ f"<body>{ whole_body } </body></html>"
60+ )
5761 self .create_email_msg (subject_msg )
5862 self .mime_msg .attach (MIMEText (msg , "html" ))
5963 smtp = smtplib .SMTP ("127.0.0.1" )
6064 smtp .sendmail (self .send_from , self .send_to , self .mime_msg .as_string ())
6165 smtp .close ()
62- print ("Sending email finished" )
63-
66+ logger .info ("Sending email finished" )
0 commit comments