Unable to retrieve gmail messages from any folder other than inbox (Python3 issue)
As it's mentioned in this answer:
Try using m.select('"[Gmail]/All Mail"'), so that the double quotes get transmitted. I suspect imaplib is not properly quoting the string, so the server gets what looks like two arguments: [Gmail]/All, and Mail.
And it works in python v3.4.1
import imaplibimport emailm = imaplib.IMAP4_SSL("imap.gmail.com", 993)m.login("myemail@gmail.com","mypassword")m.select('"[Gmail]/All Mail"')result, data = m.uid('search', None, "ALL") # search all email and return uidsif result == 'OK': for num in data[0].split(): result, data = m.uid('fetch', num, '(RFC822)') if result == 'OK': email_message = email.message_from_bytes(data[0][1]) # raw email text including headers print('From:' + email_message['From'])m.close()m.logout()