user185608
user185608

Reputation: 21

using imaplib to access corporate gmail

I have the following code, it works for my own personal email.

import getpass, imaplib
import email
import libgmail
import re

#M=imaplib.IMAP4()
M=imaplib.IMAP4_SSL('imap.gmail.com',993)
M.login('[email protected]','password')
M.select('bur-dev')

typ, data = M.search(None, 'ALL')
for num in data[0].split():
    typ, data = M.fetch(num, '(RFC822)')
    print 'Message %s\n%s\n' % (num, data[0][1])
M.close()
M.logout()

With my company mail though (I do have imap turned on) i get a connection time out-

    C:\Python24\libgmail-0.1.11>python gmail_app.py
Traceback (most recent call last):
  File "gmail_app.py", line 7, in <module>
    M=imaplib.IMAP4_SSL('imap.gmail.com',993)
  File "/usr/lib/python2.6/imaplib.py", line 1138, in __init__
    IMAP4.__init__(self, host, port)
  File "/usr/lib/python2.6/imaplib.py", line 163, in __init__
    self.open(host, port)
  File "/usr/lib/python2.6/imaplib.py", line 1149, in open
    self.sock = socket.create_connection((host, port))
  File "/usr/lib/python2.6/socket.py", line 514, in create_connection
    raise error, msg
socket.error: [Errno 116] Connection timed out

Any ideas on how to debug this? The port is not firewalled because it is working for my personal email.

Upvotes: 2

Views: 4253

Answers (2)

Keshav Metkar
Keshav Metkar

Reputation: 11

Connection is getting blocked. Following could be the probable reason:

  1. proxy is used for internet access. Python tries to connect directly.

  2. Firewall or network security appliance blocking connection

  3. Local fireall of system or AV blocking connection

Upvotes: 0

zoobert
zoobert

Reputation: 572

You seem to have a firewall issue.
Your company doesn't allow a connection to imap.gmail.com on port 993.
As suggested in one of the comment try from the commandline:
telnet imap.gmail.com 993

if it times out or goes into error then you are not allow to access that port from your machine.

Upvotes: 0

Related Questions