Advertisement
AyanUpadhaya

Send Mail IN Python

May 12th, 2021 (edited)
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.65 KB | None | 0 0
  1. import smtplib,ssl
  2.  
  3. #smtp server address
  4. smtp_server="smtp.gmail.com"
  5. port=587 #for starttls
  6.  
  7. sender_email="ayanU881@gmail.com"
  8. password=" "
  9. reciver_email="ayanupadhaya2010@gmail.com"
  10. message=input("Enter your message:")
  11. #create a secure ssl context
  12.  
  13. context=ssl.create_default_context()
  14.  
  15. #try to login to server and send mail
  16.  
  17. try:
  18.     server=smtplib.SMTP(smtp_server,port)
  19.     server.ehlo()#can be commited
  20.     server.starttls(context=context)#secure the connection
  21.     server.ehlo()
  22.     server.login(sender_email,password)
  23.     server.sendmail(sender_email,reciver_email,message)
  24. except Exception as e:
  25.     print(e)
  26.  
  27. finally:
  28.     server.quit()
  29.     print('Success')
  30.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement