import smtplib from email.mime.multipart import MIMEMultipart from email.mime.text import MIMEText from utils import format_product_table class EmailSender: def __init__(self, from_email, password): self.from_email = from_email self.password = password def send_email(self, to_email, product_info): msg = MIMEMultipart() msg['From'] = self.from_email msg['To'] = to_email msg['Subject'] = f'Lidl has your {len(product_info)} items on sale' body = format_product_table(product_info, tablefmt="html") html_content = MIMEText(body, 'html') msg.attach(html_content) server = smtplib.SMTP('smtp.gmail.com', 587) server.starttls() server.login(self.from_email, self.password) text = msg.as_string() server.sendmail(self.from_email, to_email, text) server.quit()