The program will send an email with a random Joke to the user, every morning at 8:00 AM.
In order to run the program please follow the instructions 🏁:
We need to create 3 different files
▪️ joke.py (Allows us to ask to the users to enter the data and save it in the database)
▪️ main.py (Will send an email with a random Joke to the users using smtplib and an api)
▪️ hidden.py (Containt the information about the database)
❗ IMPORTANT : Create a database connection in the file hidden with all info about the db , we will need this info in the main.py and joke.py
def db_connection():
return {"database":"",
"host":"",
"user":"",
"password":"",
"port":""}
https://official-joke-api.appspot.com/random_joke
Before to lunch the program we need to create an email ( the sender )
https://docs.python.org/3/library/smtplib.html#smtplib.SMTP.sendmail
with smtplib.SMTP("smtp.gmail.com",587, timeout=120) as connection:
connection.starttls()
connection.login(user=test_email, password=test_password)
'''
SMTP host for different email addresses:
smtp.aol.com
smtp.mail.att.net
smtp.comcast.net
smtp.mail.me.com
smtp.gmail.com
smtp-mail.outlook.com
smtp.mail.yahoo.com
'''
Then it is important to follow this example with gmail, steps by step to configure your email address
🔹1. In Your gmail Webpage, after the login, on the top right of the screen click on the icon and then Manage your Google Account
🔹2. Click on the Security/Safety
🔹3. Enable two step verification and follow the instructions from gmail
🔹4. Then go back on Security/Safety and click on Add password
🔹5. After you add the password click on Select app and chose "Other" , type a name and click on Generate
🔹6. Copy the generated password and paste it into file joke.py in test_password = ""
To run the program everyday at 8:00, we need to run the program in the could , in this case in python anywhere .
So in python anywhere add the file in the could , then start a new bash console and then schedule the task to be executed at the time that you want in this case at 8:00 AM
The Graphical User Interface ( GUI ) will look like this: