Allow sending emails
This commit is contained in:
26
mail_sender.py
Normal file
26
mail_sender.py
Normal 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()
|
||||
Reference in New Issue
Block a user