Commit d6e6cfd3 authored by Joshua Tauberer's avatar Joshua Tauberer

mail test: catch typical connecting errors and display nicer output

parent fff06f7d
......@@ -12,8 +12,18 @@ host, emailaddress, pw = sys.argv[1:4]
# Attempt to login with IMAP. Our setup uses email addresses
# as IMAP/SMTP usernames.
M = imaplib.IMAP4_SSL(host)
M.login(emailaddress, pw)
try:
M = imaplib.IMAP4_SSL(host)
M.login(emailaddress, pw)
except OSError as e:
print("Connection error:", e)
sys.exit(1)
except imaplib.IMAP4.error as e:
# any sort of login error
e = ", ".join(a.decode("utf8") for a in e.args)
print("IMAP error:", e)
sys.exit(1)
M.select()
print("IMAP login is OK.")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment