Skip to content

Instantly share code, notes, and snippets.

@tolbrino
Created October 23, 2015 07:30
Show Gist options
  • Save tolbrino/b72282188aaee1777b47 to your computer and use it in GitHub Desktop.
Save tolbrino/b72282188aaee1777b47 to your computer and use it in GitHub Desktop.
Script to check access of multiple email accounts against an IMAP host.
#!/usr/bin/env python
import sys
import imaplib
EMAIL_ACCOUNT_SUFFIX = "@mydomain.com"
EMAIL_HOST = "mail.myhost.com"
EMAIL_ACCOUNTS = {
"name": "pass",
}
for name, pw in EMAIL_ACCOUNTS.items():
print("CONNECT")
M = imaplib.IMAP4_SSL(EMAIL_HOST)
try:
account = name + EMAIL_ACCOUNT_SUFFIX
print("LOGIN " + account)
rv, data = M.login(account, pw)
except imaplib.IMAP4.error:
print ("LOGIN FAILED!!! ")
continue
print(rv, data)
rv, mailboxes = M.list()
if rv == 'OK':
print("Mailboxes:")
print(mailboxes)
M.logout()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment