We help IT Professionals succeed at work.

How to programatically poll a mail server In symbian

mubama0n
mubama0n asked
on
990 Views
Last Modified: 2013-12-27
Hello,

I'd like to create a series60 application which launches the retrieval of new mails from a mailbox.
I've been able to retrive the id of the mailbox service but I don't know how to get new mails. I have tried with the following methods:
CImPOP3GetMail::GetMailL
and CPop3ClientMtm::InvokeAsyncFunctionL
but I do not manage to make it works.

Can someone help?

Note : Dont Tell me download the (Pop3_Imap4) Example in nokia website  because my case here is different from this example
Our telecom provider is not offering the email service although that the (GPRS) is working successfully.

Please take look on this posted threads:
https://www.experts-exchange.com/Programming/Wireless_Programming/EPOC/Q_21880941.html
https://www.experts-exchange.com/Programming/Wireless_Programming/EPOC/Q_21823903.html



Thanks,
Comment
Watch Question

Author

Commented:
Here Is The Code That I Have It breacks on the line:op=pop3Mtm->InvokeAsyncFunctionL(KPOP3MTMMoveMailSelectionWhenAlreadyConnected,*selection,dummyParams,waiter->iStatus);

The Complete Code Is Here:

void CDisplayMessageFolderContainer::GetInboxEmail()
{
      //--->The Original
//----->Making Some Feltiring for Incoming Messages
      CMsvEntryFilter* aFilter=CMsvEntryFilter::NewLC();
      TMsvSelectionOrdering* selectionOrder = new (ELeave) TMsvSelectionOrdering(KMsvNoGrouping,EMsvSortByDateReverse,ETrue);
      aFilter->SetOrder(*selectionOrder);
      CMsvEntrySelection* childSelection = new(ELeave) CMsvEntrySelection;
      iSession->GetChildIdsL(KMsvGlobalInBoxIndexEntryId,*aFilter,*childSelection);
      iEntry = iSession->GetEntryL(KMsvGlobalInBoxIndexEntryId);
      CPop3ClientMtm* pop3Mtm = static_cast<CPop3ClientMtm*>(iMtmReg->NewMtmL(KUidMsgTypePOP3));
      CleanupStack::PushL(pop3Mtm);
      pop3Mtm->SwitchCurrentEntryL( iEntry->EntryId() );
//------>Setting And Saving Pop3 Account
      CImPop3Settings* tempsettings = new (ELeave) CImPop3Settings();
      CImPop3Settings &settings =tempsettings->CopyL(pop3Mtm->Settings());
      settings.Reset();
      settings.SetServerAddressL(KPOP3Server1);
      settings.SetLoginNameL(KPOP3LoginName1);
      settings.SetPasswordL(KPOP3Password1);
      settings.SetPort(KPop3Port1);
      settings.SetInboxSynchronisationLimit(0);
      settings.SetGetMailOptions(EGetPop3EmailMessages);
      CleanupStack::PushL(&settings);
      pop3Mtm->SetSettingsL(settings);
      //pop3Mtm->SwitchCurrentEntryL(iNewMessageId);
      //CMsvEntry* service=&pop3Mtm->Entry();//&clientMtm->Entry();//
      //CleanupStack::PushL( service );
      CMsvEntrySelection *selection = new(ELeave)CMsvEntrySelection;
      CleanupStack::PushL( selection );
      selection =pop3Mtm->Entry().ChildrenL();//pop3Mtm->Entry().ChildrenWithMtmL(KUidMsgTypePOP3);////service->ChildrenL();// // a selection of all entries in the mail box
      selection->AppendL(pop3Mtm->Entry().EntryId());
      //TBuf8<1> dummyParams;//dummy parameters needed for InvokesyncFunctionL
      CAknInformationNote* informationNote = new (ELeave) CAknInformationNote;
      _LIT(messageChanged,"Synchronization Will be Started");
      informationNote->ExecuteLD(messageChanged);
//---->For Asynchronouse Calls//KPOP3MTMIsConnected
//--->if we want to Use GetEmail Class
//--->
      CMsvOperation* op=NULL;
      CleanupStack::PushL(op);
      CMsvOperationWait* waiter=CMsvOperationWait::NewLC();//KPOP3MTMMoveMailSelectionWhenAlreadyConnected
      TBuf8<1> dummyParams;//KPOP3MTMConnectAndCopyMailSelectionAndDisconnect
      op=pop3Mtm->InvokeAsyncFunctionL(KPOP3MTMMoveMailSelectionWhenAlreadyConnected,*selection,dummyParams,waiter->iStatus);
      waiter->Start();
      CActiveScheduler::Start();
      CleanupStack::PopAndDestroy(waiter);
      CleanupStack::PopAndDestroy(op);
      CleanupStack::PopAndDestroy(selection);
      //if (selection != NULL)
      //{
      //CMsvOperation* op=pop3Mtm->InvokeAsyncFunctionL(KPOP3MTMConnectAndCopyMailSelectionAndDisconnect,*selection,dummyParams,stat);
      //}
      //CActiveScheduler::Start();
      _LIT(messageAfter,"Synchronization Ended");
      informationNote->ExecuteLD(messageAfter);
      //_LIT(messageAfter,"Synchronization Ended");
      //informationNote->ExecuteLD(messageAfter);
//------>
//---->End of The New Modifications
//---->Original
//---->End Of the Original
//------------------------------>Loop For Listing The Email Messages
      CDesCArray *array=(CDesCArray*)iListBox->Model()->ItemTextArray();
      CMsvEntrySelection *children=pop3Mtm->Entry().ChildrenL();//iEntry->ChildrenL();
    CleanupStack::PushL(children);
    _LIT(KItemFormat,"\t%S\t%S");
    TBuf<100> buf;
      TInt EmMesCount=0; ///--->To Count The Email Messages Not Other (e.g.:sms)
    for(TInt i=0;i<children->Count();i++)
    {
            //--->The Original
        //CMsvEntry *child=drafts->ChildEntryL((*children)[i]);
            CMsvEntry *child=pop3Mtm->Entry().ChildEntryL((*children)[i]);//iEntry->ChildEntryL((*children)[i]);
        const TMsvEntry &entry=child->Entry();
            if ( ( iSession->GetEntryL( children->At( i ) ) )->Entry().iMtm == KUidMsgTypePOP3)
            {
                  buf.Format(KItemFormat,&entry.iDescription,&entry.iDetails);
                  EmMesCount++;
            }
        delete child;
        array->AppendL(buf);
    }
      if (EmMesCount > 0)
      {
            CAknInformationNote* informationNote2 = new (ELeave)CAknInformationNote;
            informationNote2->ExecuteLD(_L("Getting Messages From Your Email"));
      }
    CleanupStack::PopAndDestroy(6);//(5); // (3)children, drafts, session
      //---->
      iListBox->Model()->SetItemTextArray(array);
      //iListBox->Model()->SetOwner
      iListBox->SetCurrentItemIndex(0);
      iListBox->SetFocus(ETrue);
}
void CDisplayMessageFolderContainer::ConstructL(const TRect& aRect)
//void CDisplayMessageFolderContainer::ConstructL(const TRect& aRect,CDisplayMessageFolderAppUi* aParent)
{      //----->New Statement
    CreateWindowL();
      iListBox=new(ELeave)CAknDoubleStyleListBox;
    iListBox->ConstructL(this,EAknListBoxSelectionList);
    iListBox->SetContainerWindowL(*this);
    //CDesCArray *array=(CDesCArray*)iListBox->Model()->ItemTextArray();
    SetRect(aRect);
    ActivateL();
      iListBox->SetSize(aRect.Size());
      iSession = CMsvSession::OpenAsyncL(*this);
      iMtmReg = CClientMtmRegistry::NewL( *iSession );
      iEntry = CMsvEntry::NewL(*iSession, KMsvGlobalInBoxIndexEntryId, TMsvSelectionOrdering());
}

void CDisplayMessageFolderContainer::HandleSessionEventL(TMsvSessionEvent aEvent, TAny* aArg1, TAny* aArg2, TAny* aArg3) //HandleSessionEventL
{
//--->To Be Added When Needed
CAknInformationNote* informationNote = new (ELeave) CAknInformationNote;
switch(aEvent)
{
// the messaging server is ready
case MMsvSessionObserver::EMsvServerReady:
{
TMsvId serviceId(KMsvRootIndexEntryId); // Pop3 service id
//TMsvId serviceId; // Pop3 service id
//serviceId=KMsvRootIndexEntryId;
// Determine if the event was succesful.
// ServiceProgress inserts TBuf8 value in progress.
TBuf8<KBfrLength> progress;
iSession->ServiceProgress( serviceId, progress );
_LIT8( KCompare, "KErrNone");
if ( progress.Compare( KCompare ))
{
//HBufC* text = StringLoader::LoadLC( "Email Session Server Starts" );
_LIT(ServerStarts,"Email Session Server Starts");
informationNote->ExecuteLD(ServerStarts);
//CleanupStack::PopAndDestroy( text );
// Check that MtmRegistry has not already been accessed.
if ( !iMtmReg )
{
iMtmReg = CClientMtmRegistry::NewL( *iSession );
//AccessMtmL();
}
if (!iEntry)
{
iEntry = CMsvEntry::NewL(*iSession, KMsvGlobalInBoxIndexEntryId, TMsvSelectionOrdering());
}
}
else
{
//HBufC* text = StringLoader::LoadLC( R_EMAIL_SESSION_ERROR );
_LIT(ServerFailed,"Email Session Server Faild To Start Error");
CAknErrorNote* errorNote = new ( ELeave ) CAknErrorNote;
errorNote->ExecuteLD(ServerFailed);
//CleanupStack::PopAndDestroy( text );
}
break;
}
//case MMsvSessionObserver::EMsvEntriesChanged:
case MMsvSessionObserver::EMsvEntriesCreated:
{
// We are interested in messages that are created in Inbox
_LIT(messageChanged,"Entries Created");
informationNote->ExecuteLD(messageChanged);
// Only look for changes in the Inbox
if (*(static_cast<TMsvId*>(aArg2)) == KMsvGlobalInBoxIndexEntryId)//KObservedFolderId)
{
CMsvEntrySelection* entries = static_cast<CMsvEntrySelection*>(aArg1);
iNewMessageId = entries->At(0);
DisplayMessageL(iNewMessageId);
}
break;
//------------>

}
//case MMsvSessionObserver::EMsvEntriesCreated:
case MMsvSessionObserver::EMsvEntriesChanged:
{
_LIT(messageCreated,"Message Entries Changed");
informationNote->ExecuteLD(messageCreated);
if (*(static_cast<TMsvId*>(aArg2)) == KMsvGlobalInBoxIndexEntryId)
{
CMsvEntrySelection* entries = static_cast<CMsvEntrySelection*>(aArg1);
if (iNewMessageId == entries->At(0))
{
// Set entry context to the new message
iEntry->SetEntryL(iNewMessageId);
// Check the type of the arrived message and that the message is complete.
// only SMS are our consern
if ( iEntry->Entry().iMtm != KUidMsgTypePOP3 || iEntry->Entry().iMtm != KUidMsgTypeIMAP4 || !iEntry->Entry().Complete() )
{
return;
}
}
// Read-only store.
//CMsvStore* store = iEntry->ReadStoreL();
//CleanupStack::PushL(store);
DisplayMessageL(iEntry->EntryId());
//CleanupStack::PopAndDestroy(store);
}
break;

}
//----->
case MMsvSessionObserver::EMsvCloseSession:
{
_LIT(messageClose,"Sesion Closed");
informationNote->ExecuteLD(messageClose);
iSession->CloseMessageServer();
break;
}
case MMsvSessionObserver::EMsvServerTerminated:
{
_LIT(messageTerminate,"Sesion Terminated");
informationNote->ExecuteLD(messageTerminate);
iSession->CloseMessageServer();
break;
}
case MMsvSessionObserver::EMsvGeneralError:
case MMsvSessionObserver::EMsvServerFailedToStart:
{
//iObserver.HandleEngineChangedEventL(MMsvObserver::EFatalServerError);
_LIT(messageError,"Error At The Messaging Server");
informationNote->ExecuteLD(messageError);
//iObserver.HandleError(MMsvObserver::EFatalServerError);
break;
}
//----->

break;
}
}

Author

Commented:
It breaks (With Run time error) on the line:
op=pop3Mtm->InvokeAsyncFunctionL(KPOP3MTMMoveMailSelectionWhenAlreadyConnected,*selection,dummyParams,waiter->iStatus);
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.