You Are Here:

Community: Wiki

This page was last modified on 12 September 2009, at 07:46.

How to retrieve e-mail contents

From Forum Nokia Wiki

Reviewer Approved   

Purpose

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

Libraries

LIBRARY  msgs.lib
LIBRARY imcm.lib

Capabilities

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);
 
mailAccount->GetPopAccountsL(accounts);
 
TInt countAccnt = accounts.Count();
TBuf<100> countAccntBuf;
countAccntBuf.AppendNum(countAccnt);
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
(*iSession,mailId,TMsvSelectionOrdering::TMsvSelectionOrdering());
CleanupStack::PushL(mailEntry);
 
//getting the children entries
CMsvEntrySelection* entries = mailEntry->ChildrenL();
CleanupStack::PushL( entries );
 
//getting no. of mails
TInt mailCount= entries->Count();
 
TBuf<100> mailCountBuf;
mailCountBuf.AppendNum(mailCount);
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);
CleanupStack::PushL(entry);
 
CMsvStore *store = entry->ReadStoreL();
CleanupStack::PushL(store);
 
CImHeader* header = CImHeader::NewLC();
header->RestoreL(*store);
 
//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;
 
paraFormatLayer=CParaFormatLayer::NewL();
charFormatLayer=CCharFormatLayer::NewL();
 
richText=CRichText::NewL(paraFormatLayer, charFormatLayer);
CleanupStack::PushL(richText);
 
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

Retrieve Mail Contents

Related Wiki Articles

No related wiki articles found

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia 
RDF Facets: qdcZidentifierQSxhttpE3aE2fE2fwikiE2eforumE2enokiaE2ecomE2findeE78E2ephpE2fE25E455E259CE25A8E25E454E25BBE25A3E25E457E25A0E2581E25E454E25B8E25AE44E25E457E2594E259FE25E456E2588E2590E25E457E2594E25B5E25E455E25AE44E2590E25E459E2582E25AE45E25E454E25BBE25B6E25E455E25B8E2590E25E456E2588E25B7X qdcZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qdcZtypeQUqfntypeZCommunityContentQ qdcZtypeQUqfntypeZE52esourceQ qdcZtypeQUqfntypeZWebpageQ qdcZtypeQUqfntypeZWikiContentQ qdcZtypeQUqmarsZManagedE52esourceQ qdcZtypeQUqwebZInformationE52esourceQ qdcZtypeQUqwebZPageQ qdcZtypeQUqwebZE52esourceQ qdcZtypeQUqrdfsZE52esourceQ qfnZtopicQUqfnTopicZemailQ qfnZtopicQUqfnTopicZmessagingQ qfnZtypeQUqfntypeZCommunityContentQ qfnZtypeQUqfntypeZE52esourceQ qfnZtypeQUqfntypeZWebpageQ qfnZtypeQUqfntypeZWikiContentQ qmarsZlanguageQUxhttpE3aE2fE2fswE2enokiaE2ecomE2flanguageE2d1E2fenX qrdfZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qrdfZtypeQUqfntypeZCommunityContentQ qrdfZtypeQUqfntypeZE52esourceQ qrdfZtypeQUqfntypeZWebpageQ qrdfZtypeQUqfntypeZWikiContentQ qrdfZtypeQUqmarsZManagedE52esourceQ qrdfZtypeQUqwebZInformationE52esourceQ qrdfZtypeQUqwebZPageQ qrdfZtypeQUqwebZE52esourceQ qrdfZtypeQUqrdfsZE52esourceQ
User Rating: qfnZuserE5FratingQNx3E2E0000X