-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnotification_manager.py
More file actions
29 lines (23 loc) · 1.12 KB
/
notification_manager.py
File metadata and controls
29 lines (23 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import smtplib
import os
from dotenv import load_dotenv
load_dotenv()
class NotificationManager:
#This class is responsible for sending notifications with the deal flight details.
def __init__(self, city):
self.destination = city
self.email = os.getenv("TEST_EMAIL")
self.password = os.getenv("TEST_EMAIL_APP_PW")
self.to_address = os.getenv("TEST_EMAIL")
self.subject = f"Low Price Alert!! Flight Deal Found to {self.destination}! ✈️"
def send_email(self, message, recipient):
"""Takes a formatted message and sends an email to the to_address specified in the envirnemnt variable."""
print(f"Deal to {self.destination} found. Sending email...")
with smtplib.SMTP("smtp.gmail.com") as connection:
connection.starttls()
connection.login(user=self.email, password=self.password)
connection.sendmail(from_addr=self.email,
to_addrs=recipient,
msg=f"Subject:{self.subject}\n\n{message}".encode("utf-8")
)
print("Email Sent!")