I have a problem with IMAP in Python 2.7
For testing purposes, I have created foobar306@gmail.com with the password testing123testing
I am following this tutorial and typed this into my Python Iteractive Shell:
Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> import imaplib
mail = imaplib.IMAP4_SSL('imap.gmail.com')
mail.login('foobar306@gmail.com', 'testing123testing')
mail.list()
# Out: list of "folders" aka labels in gmail.
mail.select("inbox") # connect to inbox.
>>>
Nothing happens, not even error messages.
Note: I have enabled IMAP in Gmail
Thanks, -tim
Update: In response to this comment:
Did you do the next section after the code you quoted above? – Amber
I tried this:
Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> import imaplib
mail = imaplib.IMAP4_SSL('imap.gmail.com')
mail.login('myusername@gmail.com', 'mypassword')
mail.list()
# Out: list of "folders" aka labels in gmail.
mail.select("inbox") # connect to inbox.
result, data = mail.search(None, "ALL")
ids = data[0] # data is a list.
id_list = ids.split() # ids is a space separated string
latest_email_id = id_list[-1] # get the latest
result, data = mail.fetch(latest_email_id, "(RFC822)") # fetch the email body (RFC822) for the given ID
raw_email = data[0] # here's the body, which is raw text of the whole email
# including headers and alternate payloads
>>>
and it still did nothing
It seems to work for me; I created a
sarnoldwasherefolder via the python API:It ought to still be there in the web interface. (Unless someone else deletes it in the meantime.)
Edit to include the full contents of the session, even including the boring bits where I re-learn The Way of Python: