-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathemail_notificator.py
36 lines (26 loc) · 931 Bytes
/
email_notificator.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
import smtplib
import ssl
from email.message import EmailMessage
def get_passes():
with open('passes.txt', 'r') as f:
file = f.readlines()
recipient = file[0].strip()
username = file[1].strip()
password = file[2].strip()
return recipient, username, password
def send_mail(data):
recipient_email, sender_email, sender_password = get_passes()
msg = EmailMessage()
msg.set_content(f'''
We found new ad(s) from olx:\n
Link(s): {data}
Message sent automatically by Olx Notifier.
Visit project at: https://github.com/kamil-gustab/Olx-Notifier
''')
msg['Subject'] = 'New ad found!'
msg['From'] = 'Olx Notifier'
msg['To'] = recipient_email
context = ssl.create_default_context()
with smtplib.SMTP_SSL("smtp.gmail.com", 465, context=context) as server:
server.login(sender_email, sender_password)
server.send_message(msg)