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.


From Wiki
Jump to: navigation, search
Article Metadata

平台: S60 3rd Edition FP1, S60 3rd Edition FP2, S60 5th Edition

关键词: CEmailAccounts, CCommsDatabase
最后由 hamishwillee 在 14 Jun 2013 编辑
  • 开发伙伴平台:S60 3rd Edition FP1, S60 3rd Edition FP2, S60 5th Edition
  • 详细描述


  • 解决方案


#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



#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 );

需要能力为: ReadDeviceData, WriteDeviceData

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