Skip to content
Permalink
Browse files
Create news-service.py
  • Loading branch information
kpakolj committed Aug 23, 2019
0 parents commit 17cd4babb81c3de322ecd4f555120e28af74a0ca
Showing 1 changed file with 80 additions and 0 deletions.
@@ -0,0 +1,80 @@
import smtplib, ssl #got this line from https://realpython.com/python-send-email/

port = 465 # For SSL #got this line from https://realpython.com/python-send-email/
# 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"]


def password():
password = input("Type your password and press enter: ")
return password


def news():
news=input("Please enter the news you want to send and press enter: ")
return news

def message():
message = """\ #got this line from https://realpython.com/python-send-email/
Subject: Daily news #got this line from https://realpython.com/python-send-email/
"""+news() #got this line from https://realpython.com/python-send-email/
return message

def send(gmail_id, 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.sendmail(gmail_id, receiver_email, message) #got this line from https://realpython.com/python-send-email/

def login(gmail_id):
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/

def remove():
n=int(input("Enter the number of email_ids you want to remove from the receivers' list"))
i=1
while(i<=n):
remove=input("Please enter an email_id to be removed then press enter")
try:
receiver_list.remove(remove)
except ValueError:
print("please enter a proper value")
i=i+1



def add():
n=int(input("Enter the number of email_ids you want to add to the receivers' list"))
i=1
while(i<=n):
add=input("Please enter an email_id to be added then press enter")
try:
receiver_list.append(add)
except ValueError:
print("please enter a proper value")
i=i+1

def main():
enter= input("Press any button to login \n")
gmail_id=input("Please enter your gmail_id and press enter: ")
login(gmail_id)
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())
elif menu=="2":
add()
elif menu=="3":
remove()
elif menu=="4":
sys.exit(0)
else:
print("please enter a proper value")




main()

0 comments on commit 17cd4ba

Please sign in to comment.