GMAIL Mailbox names for IMAP connections?

GMAIL Mailbox names for IMAP connections

I worked on something interesting today. That was "creating a simple email client for Gmail", using the PHP's built-in IMAP library. I know there is an official PHP library provided by Google for that, and I have even wrote a blog post about it sometime back (explaining about a bug I found in it). But this time I wanted to do it with the Imap library instead.

So soon after finishing the Inbox, I started working on listing the "Sent Items". But to my suprise, I had a bit hard time finding the right mailbox name for the sent items. I assumed a few names like "Sent", "Sent Items", "Sent Messages", but none of them worked. So I turned to Google and did some search, and then I found this page on the Google Developers website.

https://developers.google.com/gmail/imap/

It explains everything about Gmail and the IMAP protocol, and how to actually use IMAP with Gmail. In the IMAP Extensions page, they have listed all the mailbox names and it was just a matter of using the right name.

Here's the list:


a004 LIST "" "*"
* LIST (\HasNoChildren) "/" "INBOX"
* LIST (\Noselect \HasChildren) "/" "[Gmail]"
* LIST (\HasNoChildren \All) "/" "[Gmail]/All Mail"
* LIST (\HasNoChildren \Drafts) "/" "[Gmail]/Drafts"
* LIST (\HasNoChildren \Important) "/" "[Gmail]/Important"
* LIST (\HasNoChildren \Sent) "/" "[Gmail]/Sent Mail"
* LIST (\HasNoChildren \Junk) "/" "[Gmail]/Spam"
* LIST (\HasNoChildren \Flagged) "/" "[Gmail]/Starred"
* LIST (\HasNoChildren \Trash) "/" "[Gmail]/Trash"


https://developers.google.com/gmail/imap/imap-extensions

The mailbox name should be the name you see inside the square brackets. ex: [Gmail]/Sent Mail

Here's how to use it:

$hostname = '{imap.gmail.com:993/imap/ssl}[Gmail]/Sent Mail';

I thought I should post this in my blog, hoping that it would save someone else's time :) Please don't forget to leave a comment if it helped you. :)

3 comments :

  1. Really interesting. Next time if i'm going to connect i'll try to use this. May i suggest also some interesting information on my Gmail .

    ReplyDelete
  2. https://www.saeedhub.us/download-psiphon-for-pc-laptop-windows/

    ReplyDelete