Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries over the next few weeks. Thanks for all your past and future contributions.

How to retrieve e-mail contents

From Wiki
Jump to: navigation, search
Article Metadata
Code ExampleArticle
Created: manchb (15 Feb 2008)
Last edited: hamishwillee (06 Feb 2012)


A mail entry has different components like "From", "Subject", "Body", "Attachments", etc, The purpose of this page is to retrieve these values.

Header Files

#include <msvapi.h> //CMsvSession, CMsvEntry
#include <cemailaccounts.h> //CEmailAccounts
#include <miutmsg.h> //CImEmailMessage
#include <miuthdr.h> //CImHeader


LIBRARY  msgs.lib
LIBRARY imcm.lib


Capability ReadUserData

Code Snippets

The following code is used to create a session synchronously to message server:

 //Derive your class from "MMsvSessionObserver" and give implementation to the 
//"HandleSessionEventL(TMsvSessionEvent, TAny*, TAny*, TAny*);" method.
iSession = CMsvSession::OpenSyncL(*this);

The following code is used to construct an Email accounts object and gets a list of POP account IDs.:

 CEmailAccounts* mailAccount = CEmailAccounts::NewLC();
RArray<TPopAccount> accounts(10);
TInt countAccnt = accounts.Count();
TBuf<100> countAccntBuf;
CEikonEnv::InfoWinL(_L("Number of Accounts"), countAccntBuf);

Traverse through the available accounts and retrieve the entries in each account as done below.

The following code is used to retrieve the TMsvId of the particular account and retrieve its entries:

 //getting the TMsvId of the account
TPopAccount popAcnt = accounts.operator[](i);
TMsvId mailId = popAcnt.iPopService;
//getting the entry details in that account
CMsvEntry* mailEntry =CMsvEntry::NewL
//getting the children entries
CMsvEntrySelection* entries = mailEntry->ChildrenL();
CleanupStack::PushL( entries );
//getting no. of mails
TInt mailCount= entries->Count();
TBuf<100> mailCountBuf;
CEikonEnv::InfoWinL(_L("Number of Mails"), mailCountBuf);

The following code is used to retrieve TMsvId of each mail and get the "From" and "Subject" from it from the store:

 TMsvId entryID = entries->At(mailTraverese);
//mailTraverese is TInt starts from 0 to mailCount-1
CMsvEntry* entry= iSession->GetEntryL(entryID);
CMsvStore *store = entry->ReadStoreL();
CImHeader* header = CImHeader::NewLC();
//subject buffer contains the "subject" of the mail.
TBuf<50> subject = header->Subject();
//header buffer contains the "header" of the mail.
TBuf<50> from = header->From();
CleanupStack::PopAndDestroy(2, store);//header, store

The following code is used to retrieve the mail Body

 CRichText* richText; 
CParaFormatLayer* iParaFormatLayer;
CCharFormatLayer* iCharFormatLayer;
richText=CRichText::NewL(paraFormatLayer, charFormatLayer);
CImEmailMessage* mailMsg = CImEmailMessage::NewLC(*entry);
mailMsg->GetBodyTextL(entryID, CImEmailMessage::EThisMessageOnly,
*richText , *iParaFormatLayer, *iCharFormatLayer);
CleanupStack::PopAndDestroy(5, mailEntry);//mailMsg,richText,entry,entries,mailEntry

The following link is used to retrieve the attachment info. in the mail: Retrieve Attachment Info.

Example Project

This page was last modified on 6 February 2012, at 05:54.
33 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.


Thank you!

We appreciate your feedback.