From 9fe13c21a7ddff9ac895a04a86c83abc0ece5ba3 Mon Sep 17 00:00:00 2001 From: "Justice Kpakol (kpakolj)" Date: Tue, 27 Aug 2019 01:50:19 +0100 Subject: [PATCH] Update news-service.py --- news-service.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/news-service.py b/news-service.py index 3ad05fe..bdd6c35 100644 --- a/news-service.py +++ b/news-service.py @@ -4,7 +4,7 @@ port = 465 # For SSL #got this line from https://realpython.com/python-send-e # Create a secure SSL context context = ssl.create_default_context() #got this line from https://realpython.com/python-send-email/ -receiver_list = ["receiveremail@gmail.com"] +receiver_list = ["kpakolj@coventry.ac.uk","justicetkpakol1@gmail.com"] def password(): @@ -23,14 +23,15 @@ def message(): """+news() #got this line from https://realpython.com/python-send-email/ return message -def send(gmail_id, message): +def send(gmail_id, password,message): for receiver_email in receiver_list: with smtplib.SMTP_SSL("smtp.gmail.com", port, context=context) as server: #got this line from https://realpython.com/python-send-email/ + server.login(gmail_id, password) server.sendmail(gmail_id, receiver_email, message) #got this line from https://realpython.com/python-send-email/ -def login(gmail_id): +def login(gmail_id,password): with smtplib.SMTP_SSL("smtp.gmail.com", port, context=context) as server: #got this line from https://realpython.com/python-send-email/ - server.login(gmail_id, password()) #got this line from https://realpython.com/python-send-email/ + server.login(gmail_id, password) #got this line from https://realpython.com/python-send-email/ def remove(): n=int(input("Enter the number of email_ids you want to remove from the receivers' list")) @@ -59,11 +60,12 @@ def add(): def main(): enter= input("Press any button to login \n") gmail_id=input("Please enter your gmail_id and press enter: ") - login(gmail_id) + password_=password() + login(gmail_id,password_) while (True): menu=input("Welcome back, "+gmail_id+"\nIf you want to send an email to your subscribers, press 1 then press enter\nIf you want to add to the subscribers' list, press 2 then press enter\nIf you want to delete from the list, press 3 \nIf you want to exit, press 4 ") if menu=="1": - send(gmail_id,message()) + send(gmail_id,password_,message()) elif menu=="2": add() elif menu=="3": @@ -77,4 +79,3 @@ def main(): main() -