Skip to content
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
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 = ["kpakolj@coventry.ac.uk","justicetkpakol1@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, 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,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/
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: ")
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,password_,message())
elif menu=="2":
add()
elif menu=="3":
remove()
elif menu=="4":
sys.exit(0)
else:
print("please enter a proper value")
main()