-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathautomatednotification.py
36 lines (28 loc) · 985 Bytes
/
automatednotification.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
#!/usr/bin/env python
# coding: utf-8
import requests
import smtplib, ssl
import datetime
from bs4 import BeautifulSoup
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from keys import pwd
URL = "http://url.com"
raw = requests.get(URL)
soup = BeautifulSoup(raw.content, 'html5lib')
sender_email = "[email protected]"
password = pwd
date = datetime.datetime.now()
timestamp = date.strftime("%d-%b-%Y (%H:%M:%S.%f)")
subject = "Outstanding Customer DRs as of " + timestamp
message["Subject"] = subject
message["From"] = sender_email
message["To"] = ", ".join(receiver_email)
message.attach(MIMEText(soup.prettify(), "html"))
context = ssl.create_default_context()
with smtplib.SMTP_SSL("smtp.gmail.com", 465, context=context) as server:
server.login(sender_email, password)
server.sendmail(
sender_email, receiver_email, message.as_string()
)