I'm writing a script to grab the link from an email that my web application sends out to then start off a set of automated tests. At the minute my code should only grab the body of the email, I haven't started to scan for the link within that yet because I get no return.
import imaplib
mail = imaplib.IMAP4_SSL('imap.gmail.com')
mail.login('user', 'passwd')
mail.list()
mail.select("inbox")
result, data = mail.search(None, "ALL")
ids = data[0]
id_list = ids.split()
latest_email_id = id_list[-1]
result, data = mail.fetch(latest_email_id, "(RFC822)")
raw_email = data[0][1]
print raw_email
I don't see anything wrong in my code for getting the newest email (top of the inbox) and my IMAP is set up for the account. Can anyone enlighten me as to why I'm getting the error:
socket.error: [Errno 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond
Thanks in advance.
Edit: Company firewall is blocking port 143 and 993 (default IMAP(S) port), I've posted my workaround as the answer. There is nothing wrong with my code!