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.

Archived:Creating an email account and showing it in the Messaging application using Symbian C++

From Wiki
Jump to: navigation, search

Archived.pngArchived: This article is archived because it is not considered relevant for third-party developers creating commercial solutions today. If you think this article is still relevant, let us know by adding the template {{ReviewForRemovalFromArchive|user=~~~~|write your reason here}}.

Article Metadata
Tested with
Devices(s): Tested on Nokia N95, Nokia E66, Nokia N82,
Nokia N96, Nokia N78
Platform(s): S60 3rd Edition, FP1
S60 3rd Edition, FP2
S60 5th Edition
S60 3rd Edition FP2
S60 3rd Edition FP1
Keywords: CEmailAccounts, CImImap4Settings, CImSmtpSettings
Created: User:Technical writer 1 (20 May 2009)
Last edited: hamishwillee (14 Jun 2013)


An email IMAP4/POP3 account can be created using CEmailAccounts. This article explains what is required to make the created email account appear in the Messaging application.


The following sample code shows how to define IMAP4 and SMTP settings, create a new email account, and display the new mailbox in the Messaging application.

  #include <commdb.h>         // link against commdb.lib 
#include <cemailaccounts.h> // link against imcm.lib
#include <cdbpreftable.h> // for CCommsDbConnectionPrefTableView
#include <iapprefs.h> // for CImIAPPreferences, TImIAPChoice
#include <imapset.h> // for CImImap4Settings
#include <smtpset.h> // for CImSmtpSettings
CEmailAccounts* emailAccs = CEmailAccounts::NewLC();
// Read settings from the connection preference table
CCommsDatabase *commsDB = CCommsDatabase::NewL( EDatabaseTypeIAP );
CleanupStack::PushL( commsDB );
CCommsDbConnectionPrefTableView* apView =
commsDB->OpenConnectionPrefTableInRankOrderLC( ECommDbConnectionDirectionUnknown );
CCommsDbConnectionPrefTableView::TCommDbIapConnectionPref firstPref;
apView->ReadConnectionPreferenceL( firstPref );
CleanupStack::PopAndDestroy( 2, commsDB ); // apView, commsDB
// Use the same preferences for the mail service
TImIAPChoice apChoice;
apChoice.iIAP = firstPref.iBearer.iIapId;
apChoice.iDialogPref = ECommDbDialogPrefPrompt;
// Add an access point for the mail service
CImIAPPreferences* apPrefs = CImIAPPreferences::NewLC();
apPrefs->AddIAPL( apChoice );
// Create Imap4 settings
CImImap4Settings *imap4Settings = new ( ELeave ) CImImap4Settings;
CleanupStack::PushL( imap4Settings );
_LIT8( KImap4User, "Username" );
_LIT8( KImap4Pwd, "Password" );
imap4Settings->SetLoginNameL( KImap4User );
imap4Settings->SetPasswordL( KImap4Pwd );
imap4Settings->SetAutoSendOnConnect( EFalse );
imap4Settings->SetImapIdle( ETrue );
imap4Settings->SetDisconnectedUserMode( ETrue );
imap4Settings->SetDeleteEmailsWhenDisconnecting( EFalse );
imap4Settings->SetAcknowledgeReceipts( EFalse );
imap4Settings->SetMaxEmailSize( KMaxTInt );
imap4Settings->SetGetMailOptions( EGetImap4EmailHeaders );
// Incoming mail server settings
_LIT( KImap4SrvAddress,"mail.address" );
_LIT( KAccountName, "Imap4 account" );
imap4Settings->SetServerAddressL( KImap4SrvAddress );
imap4Settings->SetPort( KIMAPDefaultPortNumber );
imap4Settings->SetSecureSockets( EFalse );
TImapAccount imapaccount =
emailAccs->CreateImapAccountL( KAccountName,
*apPrefs, EFalse );
// Create Smtp settings
CImSmtpSettings *smtpSettings = new ( ELeave ) CImSmtpSettings;
CleanupStack::PushL( smtpSettings );
_LIT( KEmailAddress, "myaddr@smtp.address");
_LIT( KReplyToAddress, "myaddr@smtp.address");
_LIT( KReceiptAddress, "myaddr@smtp.address");
_LIT8( KSmtpLogin, "loginname" );
_LIT8( KSmtpPass, "password");
smtpSettings->SetEmailAddressL( KEmailAddress );
smtpSettings->SetReplyToAddressL( KReplyToAddress );
smtpSettings->SetReceiptAddressL( KReceiptAddress );
smtpSettings->SetLoginNameL( KSmtpLogin );
smtpSettings->SetPasswordL( KSmtpPass );
smtpSettings->SetRequestReceipts( ETrue );
smtpSettings->SetSendCopyToSelf( ESendCopyAsBccRecipient );
smtpSettings->SetSendMessageOption( ESendMessageImmediately );
// Outbound mail server settings
_LIT( KServerAddress, "serversmtp.address");
smtpSettings->SetServerAddressL( KServerAddress );
smtpSettings->SetPort( KSMTPDefaultPortNumber );
smtpSettings->SetSecureSockets( EFalse );
// Create Smtp account
TSmtpAccount smtpaccount =
emailAccs->CreateSmtpAccountL( imapaccount,
EFalse );
emailAccs->SetDefaultSmtpAccountL( smtpaccount );
CleanupStack::PopAndDestroy( 4 ); // smtpSettings, imap4Settings,
// apPrefs, emailAccs

Note that if some SMTP settings are not set, the Messaging application crashes when the created mailbox is opened manually in some S60 3rd Edition, FP1 devices.

The following piece of code allows the new mailbox to be shown in the Messaging application. The class from which this code is called should implement the MMsvSessionObserver interface.

  #include <msvapi.h>         // link against msgs.lib
CMsvSession* msgSession = CMsvSession::OpenSyncL( *this );
CleanupStack::PushL( msgSession );
_LIT( KDescription, "dummy" );
CMsvEntry* cEntry = msgSession->GetEntryL( imapaccount.iImapService );
CleanupStack::PushL( cEntry );
TMsvEntry tEntry = cEntry->Entry();
tEntry.iDescription.Set( KDescription );
cEntry->ChangeL( tEntry );
CleanupStack::PopAndDestroy( cEntry );

Required capabilities: ReadDeviceData, WriteDeviceData

This page was last modified on 14 June 2013, at 06:57.
118 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.