Advertisement
themaleem

Untitled

Aug 15th, 2023
18
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. import smtplib, ssl
  2.  
  3. smtp_server = "smtp.gmail.com"
  4. port = 587 # For starttls
  5. sender_email = "my@gmail.com"
  6. password = input("Type your password and press enter: ")
  7.  
  8. # Create a secure SSL context
  9. context = ssl.create_default_context()
  10.  
  11. # Try to log in to server and send email
  12. try:
  13. server = smtplib.SMTP(smtp_server,port)
  14. server.ehlo() # Can be omitted
  15. server.starttls(context=context) # Secure the connection
  16. server.ehlo() # Can be omitted
  17. server.login(sender_email, password)
  18. # TODO: Send email here
  19. except Exception as e:
  20. # Print any error messages to stdout
  21. print(e)
  22. finally:
  23. server.quit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement