Namespaces

Variants
Actions

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
翻译:
hoolee
最后由 hamishwillee 在 14 Jun 2013 编辑
  • 开发伙伴平台:S60 3rd Edition FP1, S60 3rd Edition FP2, S60 5th Edition
  • 详细描述

我们可以通过CEmailAccounts生成一个IMAP4/POP3帐号,本文讲述了如何将建立的新帐号显示在信息程序。


  • 解决方案

下列实例代码演示了如何定义IMAP4和SMTP设置信息,并生成一个邮件帐号,显示在信息程序的电子邮件栏中。

#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


注意,有些SMTP设置无法设置,在某些S60第三版FP1手机上手动打开生成的电子信箱后信息程序便会崩溃。

下列代码允许新的邮箱显示在信息程序中,此代码中的类将被我们完成后的MMsvSessionObserver接口调用

#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.
79 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.

×