-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
39 lines (28 loc) · 1.19 KB
/
main.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
# Motivational Quotes Automation App
import smtplib
import random
from datetime import datetime
# --------------------------- CONSTANTS ------------------------------ #
SENDER_EMAIL = "Your Email id Here"
SENDER_PASSWORD = "Your Email Password Here"
RECIEVER_EMAIL = "Recievers Email id here"
# -------------------------- Fetch Quotes ------------------------- #
def fetch_quotes():
"""Generates random quote from quote.txt file"""
with open("quotes.txt") as file:
for _ in range(random.randint(1, 102)):
data = file.readline()
return data
# ------------------- setting up Email-SMTP ------------------- #
def send_email():
# you can put your host email smtp code here
# i have given gmail smtp as an example here
with smtplib.SMTP("smtp.gmail.com") as connection:
connection.login(user=SENDER_EMAIL, password=SENDER_PASSWORD)
connection.starttls()
connection.sendmail(from_addr=SENDER_EMAIL, to_addrs=RECIEVER_EMAIL,
msg=f"Subject:Quote for the day\n\n{fetch_quotes()}")
# calling and executing the function
# first change the constants to correct Credentials
# or else you will get error's
send_email()