2018-11-13 18:06:31 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
import smtplib #import stmplib
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
server = smtplib.SMTP("smtp.gmail.com", 587) #establshing server connection
|
|
|
|
server.ehlo()
|
|
|
|
server.starttls()
|
|
|
|
print("SERVER CONNECTED")
|
|
|
|
except:
|
|
|
|
print("Could Not connect to Gmail") #in case of failure
|
|
|
|
|
|
|
|
user = input("Enter User id\n") #YOUR ID
|
|
|
|
Pass_w = input("\nEnter your Password\n") #YOUR Password
|
2021-10-11 19:51:10 +00:00
|
|
|
receiver_id = input("\nEnter reciever id\n") #Reciever ID
|
2018-11-13 18:06:31 +00:00
|
|
|
msg = input("\nEnter message\n") #message
|
|
|
|
|
|
|
|
try:
|
|
|
|
server.login(user, Pass_w) #user log in
|
|
|
|
print("User Logged in")
|
|
|
|
except:
|
|
|
|
print("Allow Less secure apps in GOOGLE ACCOUNT SETTINGS to use SMTP services")
|
|
|
|
server.quit()
|
|
|
|
exit()
|
|
|
|
|
2021-10-11 19:51:10 +00:00
|
|
|
server.sendmail(user, receiver_id, msg)
|
2018-11-13 18:06:31 +00:00
|
|
|
print("MAIL sent") #confirmation
|
|
|
|
|
|
|
|
|
|
|
|
print("Closing Connection")
|
|
|
|
server.quit() #closing server connection
|
|
|
|
print("Server closed")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|