user1387717
user1387717

Reputation: 1049

python imaplib unexpected response 220

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?

Upvotes: 2

Views: 3270

Answers (2)

user1387717
user1387717

Reputation: 1049

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')

Upvotes: 2

tripleee
tripleee

Reputation: 189297

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

Upvotes: 2

Related Questions