From 6c1a4d8b2d7d0e2c2cad0bd759a59287824995a9 Mon Sep 17 00:00:00 2001 From: "Ahmad Koki (kokia)" Date: Sun, 18 Aug 2019 00:48:11 +0100 Subject: [PATCH] Update smtp.py --- smtp.py | 52 +++++++++++++++++++++++++++++++++------------------- 1 file changed, 33 insertions(+), 19 deletions(-) diff --git a/smtp.py b/smtp.py index 9f9caaf..02bbedc 100644 --- a/smtp.py +++ b/smtp.py @@ -1,23 +1,37 @@ -from email.mime.multipart import MIMEMultipart -from email.mime.text import MIMEText -import smtplib #calling the smtp library +import smtplib, sys #calling the smtp library +receivers=["ahmadkoki.trading@yahoo.com","ahmadkoki.jobs@yahoo.com"] #list of recievers +def send_email(): + userName = input("Enter your Gmail: ") #sender's email address + passWord = input("Enter your pssword: ") #sender's password + message = input("Enter your message here: ") #message displayes to recievers -def send_email(subject, message, receivers): - - server = smtplib.SMTP_SSL('smtp.gmail.com', 465) #establishing connecton to the gmail smtp server - server.login(userName, passWord) #giving your log in details, gotten from https://www.afternerd.com/blog/how-to-send-an-email-using-python-and-smtplib/ - for receiver_email in receivers: #iterating through the list of recievers - server.sendmail(userName, receivers, message) #sending an email to the reciever - server.quit() + server = smtplib.SMTP_SSL('smtp.gmail.com', 465) #establishing connecton to the gmail smtp server + server.login(userName, passWord) #giving your log in details, gotten from https://www.afternerd.com/blog/how-to-send-an-email-using-python-and-smtplib/ + + + server.sendmail(userName, receivers, message) #sending an email to the reciever + server.quit() #ending the program -if __name__ == "__main__": - receivers = ["ahmadkoki.trading@yahoo.com","ahmadkoki.jobs@yahoo.com"] #list of recievers - userName = input("Enter your Gmail: ") #Will ask for sender's email address - passWord = input("Enter your pssword: ") #Will ask for sender's password - subject = input("Enter message subject: ") #Will ask for email subject - message = input("Enter your message here: ") #Will ask for email message displayes to recievers -send_email(subject, message, receivers) - - + +ans=True +while ans: #used an infinitre while loop to keep the menu running + print("1.Add an email\n2.Delete an email\n3.Send an email\n4.Exit/Quit") + ans=input("What would you like to do?") + if ans=="1": + x=input("Enter the email ID you would like to add") + receivers.append(x) #adds the new email ID tot he list + print("\n Email Added") + elif ans=="2": + x=input("Enter the email ID you would like to delete") + receivers.remove(x) #removes the particuler email ID entered + print("\n Email Deleted") + elif ans=="3": + send_email() #calls the function send_email which was defined earleir + print("\n Email sent") + elif ans=="4": + sys.exit(0) #ends teh program + print("\n Goodbye") + elif ans !="": + print("\n Not Valid Choice Try again")