-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathalert.py
41 lines (33 loc) · 1.08 KB
/
alert.py
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
38
39
40
41
from __main__ import *
import smtplib
import ssl
from datetime import datetime
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
# connection port for SSL
port = 465
# account login & password (of dummy account)
login = ""
password = ""
context = ssl.create_default_context()
# Email information
sender = "AlertMonitoringSystem@gmail.com"
reciever = login
# alternate version allows for html option for hyperlinks
message = MIMEMultipart("alternative")
message["Subject"] = "Best Buy Product In Stock"
text = """ Your product is in stock now!
Time:{}""".format(datetime.now())
# Product link taken from webscraper.py
htmlMessage = """\
<html>
<body>
<p>Your <a href="{}">product</a> is in stock now!
Time:{}""".format(productLink, datetime.now())
part1 = MIMEText(text, "plain")
part2 = MIMEText(htmlMessage, "html")
message.attach(part1)
message.attach(part2)
with smtplib.SMTP_SSL("smtp.gmail.com", port, context=context) as server:
server.login(login, password)
server.sendmail(sender, reciever, message.as_string())