2

I have the following line of code using imaplib

M = imaplib.IMAP4('smtp.gmail.com', 587)

I get the following error from imaplib: abort: unexpected response: '220 mx.google.com ESMTP o13sm12303588vde.21'

However from reading elsewhere, it seems that that response is the correct response demonstrating that the connection was made to the server successfully at that port.

Why is imaplib giving this error?

4

2 回答 2

2

You are connecting to the wrong port. 587 is authenticated SMTP, not IMAP; the IMAP designated port number is 143 (or 993 for IMAPS).

于 2012-11-14T20:46:39.580 回答
2

I realized I needed to do IMAP4_SSL() - has to be SSL for IMAP and for using IMAP I need the IMAP server for gmail which is imap.googlemail.com. I ultimately got it work without specifying a port. So, final code is:

M = imaplib.IMAP4_SSL('imap.googlemail.com')

于 2012-11-15T14:51:07.987 回答