Guest User

Untitled

a guest
Nov 30th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. #!/usr/bin/python3
  2.  
  3. import imaplib
  4.  
  5. # If you need to use SSL/TLS encrypted secure connections,
  6. # then set this to True
  7. SSL_ENABLED = False
  8.  
  9. # Change this to be your IMAP server hostname.
  10. IMAP_SERVER = 'hostname'
  11.  
  12. # Change this if you listen on a nonstandard-port.
  13. # 143 (non-SSL/TLS) and 993 (SSL/TLS) are standard ports.
  14. # Don't change if you use those ports.
  15. IMAP_PORT = None
  16.  
  17. # Change these accordingly.
  18. USERNAME = 'username'
  19. PASSWORD = 'password'
  20.  
  21.  
  22. if __name__ == "__main__":
  23. try:
  24. print("Connecting to mail server...")
  25. if SSL_ENABLED:
  26. conn = imaplib.IMAP4_SSL(IMAP_SERVER, IMAP_PORT if IMAP_PORT else 993)
  27. else:
  28. conn = imaplib.IMAP4(IMAP_SERVER, IMAP_PORT if IMAP_PORT else 143)
  29.  
  30. print("Connected to server.\n")
  31. except:
  32. print("Could not connect to mail server.\n")
  33. exit(1)
  34.  
  35. try:
  36. print("Attempting to login...")
  37. data = conn.login(USERNAME, PASSWORD)
  38. if data[0].lower() == 'ok':
  39. print("Logged in successfully.\n")
  40. else:
  41. raise Exception("Login failure.\n")
  42. except:
  43. print("Could not login to mail server. Make sure you are using the proper credentials.\n")
  44. exit(2)
  45.  
  46. print("Connected and logged in without issue.")
  47. exit()
Add Comment
Please, Sign In to add comment