anyone here can tell me if my python code is well written or i'm missing some good python pattern ? ```py import smtplib from email.mime.multipart import MIMEMultipart from email.mime.text import MIMEText import os class EmailSender: def __init__(self, smtp_server, smtp_port, smtp_username, smtp_password): self.smtp_server = smtp_server self.smtp_port = smtp_port self.smtp_username = smtp_username self.smtp_password = smtp_password def send_email(self, from_address, to_address, subject, body): msg = MIMEMultipart() msg['From'] = from_address msg['To'] = to_address msg['Subject'] = subject msg.attach(MIMEText(body, 'plain')) try: server = smtplib.SMTP(self.smtp_server, self.smtp_port) server.starttls() server.login(self.smtp_username, self.smtp_password) server.sendmail(from_address, to_address, msg.as_string()) print("Email sent successfully!") except Exception as e: print(f"Failed to send email: {e},") finally: server.quit() if __name__ == '__main__': # Load environment variables smtp_username = os.getenv('SMTP_USERNAME') smtp_password = os.getenv('SMTP_PASSWORD') if not smtp_username or not smtp_password: print("SMTP_USERNAME and SMTP_PASSWORD environment variables must be set") else: email_sender = EmailSender( smtp_server='smtp.gmail.com', smtp_port=587, smtp_username=smtp_username, smtp_password=smtp_password ) email_sender.send_email( from_address=smtp_username, to_address='recipient@domain.tld', subject='Happy New Year', body='Be happy!' ) ```
also, typehints