Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I am trying to add a python script to a shared web hosting account and I cannot get even the most basic of scripts to establish a valid imap connection to gmail. Just as a test case, I created the following script:

import imaplib
conn = imaplib.IMAP4_SSL("imap.gmail.com", 993)
conn.login(<EMAIL_ADDRESS>, <PASSWORD>)

This produces the following ouput:

Traceback (most recent call last):
File "imapTest.py", line 2, in ? conn = imaplib.IMAP4_SSL("imap.gmail.com", 993) File "/usr/lib64/python2.4/imaplib.py", line 1101, in init IMAP4.init(self, host, port) File "/usr/lib64/python2.4/imaplib.py", line 160, in init self.open(host, port) File "/usr/lib64/python2.4/imaplib.py", line 1113, in open self.sock.connect((host, port)) File "", line 1, in connect socket.error: (110, 'Connection timed out')

How would I go about troubleshooting this issue? Is it possible that my hosting provider is blocking outgoing imap requests?

share|improve this question

1 Answer 1

up vote 1 down vote accepted

TELNET is always a good general purpose TCP testing tool that's available out-of-the-box on most OS's.

Can you TELNET to imap.gmail.com, port 993, from the shell on your hosted box and get an open TCP connection? If not, I'd start talking to the host about whether or not they're blocking that traffic.

Edit:

To test connectivity to an arbitrary TCP port with TELNET you need to specify the port number on the TELNET command like. For port 993, for example:

telnet imap.gmail.com 993

If you don't specify a port number the default port for TELNET, port 23, is assumed.

share|improve this answer
    
I tried to test the connection with telnet, but it isn't working. The output is as follows. Trying 74.125.157.109... telnet: connect to address 74.125.157.109: Connection timed out telnet: Unable to connect to remote host: Connection timed out That appears to be correct IP address, but the connection obviously isn't established. –  sglantz Jul 16 '10 at 12:53
    
Sorry about the formatting in the above post. After more testing it appears that no telnet connection is working. I tried connecting to serverfault.com and I received the same output expect the IP address was 69.59.196.212. –  sglantz Jul 16 '10 at 13:09
    
I'm dropping on an edit re: thee comments. –  Evan Anderson Jul 16 '10 at 13:13
    
Oops, sorry about that mistake. Still no connection with imap.gmail.com on port 993, but I can establish other connections on port 80. –  sglantz Jul 16 '10 at 13:35
    
Sounds like your outbound connections are being filtered by something, then. –  Evan Anderson Jul 16 '10 at 13:49

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.