You Are Here:

Community: Wiki


TSS001385 - Creating an email account and showing it in the Messaging application

From Forum Nokia Wiki



ID TSS001385 Creation date May 20, 2009
Platform S60 3rd Edition, FP1
S60 3rd Edition, FP2
S60 5th Edition
Devices Tested on Nokia N95, Nokia E66, Nokia N82,
Nokia N96, Nokia N78
Category Symbian C++ Subcategory Messaging, Email


Keywords (APIs, classes, methods, functions): CEmailAccounts, CImImap4Settings, CImSmtpSettings

Description

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.

Solution

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 );
apView->GotoFirstRecord();
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->Reset();
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,
*imap4Settings,
*apPrefs, EFalse );
 
// Create Smtp settings
CImSmtpSettings *smtpSettings = new ( ELeave ) CImSmtpSettings;
CleanupStack::PushL( smtpSettings );
smtpSettings->Reset();
_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,
*smtpSettings,
*apPrefs,
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

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: qdcZidentifierQSxhttpE3aE2fE2fwikiE2eforumE2enokiaE2ecomE2findeE78E2ephpE2fTSC000016E5fE2dE5fE45E2dmailE5fconfigurationE5fusingE5fOMAE5fclientE5fprovisioningE5fisE5frejectedE5fbyE5ftheE5fdeviceX qdcZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qdcZtypeQUqfntypeZCommunityContentQ qdcZtypeQUqfntypeZKnowledgeBaseContentQ qdcZtypeQUqfntypeZE52esourceQ qdcZtypeQUqfntypeZTechnicalSolutionQ qdcZtypeQUqfntypeZWebpageQ qdcZtypeQUqfntypeZWikiContentQ qdcZtypeQUqmarsZManagedE52esourceQ qdcZtypeQUqwebZInformationE52esourceQ qdcZtypeQUqwebZPageQ qdcZtypeQUqwebZE52esourceQ qdcZtypeQUqrdfsZE52esourceQ qfnZtopicQUqfnTopicZemailQ qfnZtopicQUqfnTopicZmessagingQ qfnZtypeQUqfntypeZCommunityContentQ qfnZtypeQUqfntypeZKnowledgeBaseContentQ qfnZtypeQUqfntypeZE52esourceQ qfnZtypeQUqfntypeZTechnicalSolutionQ qfnZtypeQUqfntypeZWebpageQ qfnZtypeQUqfntypeZWikiContentQ qfnZuserE5ftagQSxmessagingX qmarsZlanguageQUxhttpE3aE2fE2fswE2enokiaE2ecomE2flanguageE2d1E2fenX qrdfZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qrdfZtypeQUqfntypeZCommunityContentQ qrdfZtypeQUqfntypeZKnowledgeBaseContentQ qrdfZtypeQUqfntypeZE52esourceQ qrdfZtypeQUqfntypeZTechnicalSolutionQ qrdfZtypeQUqfntypeZWebpageQ qrdfZtypeQUqfntypeZWikiContentQ qrdfZtypeQUqmarsZManagedE52esourceQ qrdfZtypeQUqwebZInformationE52esourceQ qrdfZtypeQUqwebZPageQ qrdfZtypeQUqwebZE52esourceQ qrdfZtypeQUqrdfsZE52esourceQ