Allow sending emails

This commit is contained in:
2024-01-30 20:23:01 +01:00
parent b7f71ab9f2
commit d6da261c17
3 changed files with 44 additions and 8 deletions

26
mail_sender.py Normal file
View File

@@ -0,0 +1,26 @@
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'] = 'Items in action'
body = format_product_table(product_info)
msg.attach(MIMEText(body, 'plain'))
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()