Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python3
- import imaplib
- # If you need to use SSL/TLS encrypted secure connections,
- # then set this to True
- SSL_ENABLED = False
- # Change this to be your IMAP server hostname.
- IMAP_SERVER = 'hostname'
- # Change this if you listen on a nonstandard-port.
- # 143 (non-SSL/TLS) and 993 (SSL/TLS) are standard ports.
- # Don't change if you use those ports.
- IMAP_PORT = None
- # Change these accordingly.
- USERNAME = 'username'
- PASSWORD = 'password'
- if __name__ == "__main__":
- try:
- print("Connecting to mail server...")
- if SSL_ENABLED:
- conn = imaplib.IMAP4_SSL(IMAP_SERVER, IMAP_PORT if IMAP_PORT else 993)
- else:
- conn = imaplib.IMAP4(IMAP_SERVER, IMAP_PORT if IMAP_PORT else 143)
- print("Connected to server.\n")
- except:
- print("Could not connect to mail server.\n")
- exit(1)
- try:
- print("Attempting to login...")
- data = conn.login(USERNAME, PASSWORD)
- if data[0].lower() == 'ok':
- print("Logged in successfully.\n")
- else:
- raise Exception("Login failure.\n")
- except:
- print("Could not login to mail server. Make sure you are using the proper credentials.\n")
- exit(2)
- print("Connected and logged in without issue.")
- exit()
Add Comment
Please, Sign In to add comment