Listing, Accessing and Launching Mailboxes

This section describes how to list, access and launch mailboxes using Email Client APIs.

Email Client provides MEmailMailbox::GetMailboxesL() method to list all the mailboxes. MEmailMailbox::ShowInboxL() method is used to launch a specific mailbox in the email application.

  1. Create an instance of MEmailClientApi class.
    EmailInterfaceFactory* factory = CEmailInterfaceFactory::NewL();
    CleanupStack::PushL( factory );
    MEmailClientApi* mailClient = static_cast<MEmailClientApi*>(factory->InterfaceL( KEmailClientApiInterface ) );
  2. Get the mailboxes using MEmailMailbox::GetMailboxesL(RMailboxPtrArray& aMailboxes).
    RMailboxPtrArray mailboxes;
    CCleanupResetAndRelease<MEmailMailbox>::PushL( mailboxes );
    mailClient->GetMailboxesL( mailboxes );
    
  3. Launch the inbox using MEmailMailbox::ShowInboxL().
    mailbox->ShowInboxL();

    To access a mailbox using its address, use MEmailMailbox::MailboxL( const TPtrC& aAddress) method.

The following code snippet shows an example of how to list the mailboxes.

TInt CEmailClientApiTester::GetMailboxListL( CItemParser& /*aItem*/ )
	{
		TInt ret(KErrNone);

		CEmailInterfaceFactory* factory = CEmailInterfaceFactory::NewL();
		CleanupStack::PushL( factory );
		MEmailClientApi* mailClient = static_cast<MEmailClientApi*>(factory->InterfaceL( KEmailClientApiInterface ) );
		if ( mailClient )
			{
				CleanupReleasePushL( *mailClient );
				RMailboxPtrArray mailboxes;
				mailClient->GetMailboxesL( mailboxes );// Get the mailboxes
				for ( TInt i = 0; i < mailboxes.Count(); i++ )
					{
						MEmailMailbox* mailbox = mailboxes[i];
						iLog->Log( _L( "%S id=%d" ), &mailbox->MailboxName(), mailbox->MailboxId().iId );            
						mailbox->Release(); //Release the memory
					}
				mailboxes.Close();
				CleanupStack::PopAndDestroy();// mailClient
			}
		CleanupStack::PopAndDestroy(factory);     
		return ret;
	}
Related concepts
Email Client API Overview