-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnotification_manager.py
More file actions
37 lines (30 loc) · 1.17 KB
/
notification_manager.py
File metadata and controls
37 lines (30 loc) · 1.17 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
30
31
32
33
34
35
36
37
import os
from dotenv import load_dotenv
from twilio.rest import Client
import smtplib
load_dotenv()
account_sid = os.getenv("TWILIO_ACCOUNT_SID")
auth_token = os.getenv("TWILIO_AUTH_TOKEN")
class NotificationManager:
def __init__(self):
self.client = Client(account_sid, auth_token)
self.my_email = os.environ["MY_EMAIL"]
self.app_password = os.environ["MY_APP_PASSWORD"]
def send_whatsapp(self, msg_body):
message = self.client.messages.create(
from_="whatsapp:+14155238886",
body=msg_body,
to="whatsapp:+12055677883"
)
print(message.sid)
def send_email(self, customer_emails, email_body):
connection = smtplib.SMTP(host="smtp.gmail.com", port=587)
with connection:
connection.starttls()
connection.login(user=self.my_email, password=self.app_password)
for email in customer_emails:
connection.sendmail(
from_addr=self.my_email,
to_addrs=email,
msg=f"Subject: Low Price Alert!\n\n{email_body}".encode("utf-8")
)