Question

I'm working on an iOS app that is supposed to read and send mails. For accessing inbox folder I've used the "INBOX". It worked well for Yahoo and AOL but not Gmail. Someone told me to try "[Gmail]" , "[Gmail]/All Mails", "Gmail/[All Mails]". I've tried all of these but none of them is working. And importantly if I write "[Gmail]/Spam" or "[Gmail]/Trash" it works fine. So the point is that I can access mails of all folders except inbox. How can I access gmail's inbox folder?

Was it helpful?

Solution 2

Solved the issue with

"[Gmail]/All Mail"

OTHER TIPS

Using "Inbox" works for me for accessing GMail with python3 and imaplib. Here's how you can get the list of all valid folder names and make sure:

import imaplib
mail = imaplib.IMAP4_SSL('imap.gmail.com')
mail.login('username', 'password')
print(mail.list())

For me, some of the returned values are: "INBOX" (the inbox), "PERSONAL" (a label), "[Gmail]/Drafts" (GMail drafts), "[Gmail]/Sent Mail" (GMail sent items).

After logging in, just select the "Inbox" folder and search the contents of the folder using a query. For example, this will return a list of subjects for the e-mails in the "Inbox" folder:

# mail is the imap object from the previous listing
mail.select('"INBOX"')
result, data = mail.search(None, "ALL")

for e_id in data[0].split()[-10:]:
    _, response = mail.fetch(e_id, '(body[header.fields (subject)])')
    print(response[0][1][9:])

The reason why "[Gmail]/Drafts" might be succeeding while "[Gmail]/Sent Mail" is failing for you is that you're not quoting folder names that have whitespaces with surrounding double quotes. Here's how you can do it in python3:

# mail is the imap object from the previous listing
mail.select('"[Gmail]/Sent Mail"') # notice the double quotes as a part of the folder name
result, data = mail.search(None, "ALL")
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top