|
1 <?xml version="1.0" encoding="utf-8"?> |
|
2 <!-- Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies) All rights reserved. --> |
|
3 <!-- This component and the accompanying materials are made available under the terms of the License |
|
4 "Eclipse Public License v1.0" which accompanies this distribution, |
|
5 and is available at the URL "http://www.eclipse.org/legal/epl-v10.html". --> |
|
6 <!-- Initial Contributors: |
|
7 Nokia Corporation - initial contribution. |
|
8 Contributors: |
|
9 --> |
|
10 <!DOCTYPE task |
|
11 PUBLIC "-//OASIS//DTD DITA Task//EN" "task.dtd"> |
|
12 <task id="GUID-FC308B84-E109-48F3-90F1-78F0C837CC56" xml:lang="en"><title>Creating, |
|
13 Replying and Forwarding Email Messages</title><shortdesc>This section describes how to draft, reply and forward email messages |
|
14 using Email Client APIs.</shortdesc><prolog><metadata><keywords/></metadata></prolog><taskbody> |
|
15 <prereq id="GUID-DFD5B648-D3A3-443A-AC0E-622A63E79D70"><p>Perform the steps |
|
16 described in <xref href="GUID-1DCB0B64-0B70-4F34-81A7-E00A996AD626.dita">Listing, |
|
17 Accessing and Launching Mailboxes</xref>.</p></prereq> |
|
18 <context id="GUID-BB5FA642-AF84-41B0-AAD7-B2D32CECC477"> <p>There are |
|
19 three ways to create messages:</p><ul> |
|
20 <li><p>Creating a draft message by drafting a new email.</p></li> |
|
21 <li><p>Creating a reply message by replying to an existing email.</p></li> |
|
22 <li><p>Creating a forward message by forwarding an existing email.</p></li> |
|
23 </ul> </context> |
|
24 <steps id="GUID-4DD07DEC-6017-4237-BE46-1D69E5FBD744-GENID-1-10-1-7-1-1-4-1-3-1-5-1-5-1-3-3"> |
|
25 <step id="GUID-9A69E5AD-E938-4092-A8C2-CB65C37C8962-GENID-1-10-1-7-1-1-4-1-3-1-5-1-5-1-3-3-1"><cmd>Create a message.</cmd> |
|
26 <info><p>Messages can be created using one of the following methods:</p></info> |
|
27 <choices> |
|
28 <choice><p>Create a new draft message.</p><codeblock xml:space="preserve">MEmailMailbox* mailbox = mailboxes[i]; |
|
29 MEmailMessage* message = mailbox->CreateDraftMessageL(); |
|
30 CleanupReleasePushL(*message); |
|
31 </codeblock></choice> |
|
32 <choice><p>Create a reply message.</p><codeblock xml:space="preserve">MEmailMailbox* mailbox = mailboxes[i]; |
|
33 MEmailMessage* message = mailbox->CreateReplyMessageL(); |
|
34 CleanupReleasePushL(*message); |
|
35 </codeblock></choice> |
|
36 <choice><p>Create a forward message.</p><codeblock xml:space="preserve">MEmailMailbox* mailbox = mailboxes[i]; |
|
37 MEmailMessage* message = mailbox->CreateForwardMessageL(); |
|
38 CleanupReleasePushL(*message); |
|
39 </codeblock></choice> |
|
40 </choices> |
|
41 </step> |
|
42 </steps> |
|
43 <example><p>The following code snippet shows an example of how to create a |
|
44 draft email message.</p><p><codeblock xml:space="preserve">TInt CEmailClientApiTester::CreateDraftMessageL( CItemParser& /*aItem*/ ) |
|
45 { |
|
46 |
|
47 TInt ret( KErrNone); |
|
48 MEmailClientApi* mailClient = CreateFactoryAndClientApiLC(); |
|
49 RMailboxPtrArray mailboxes; |
|
50 CleanupResetAndRelease<MEmailMailbox>::PushL( mailboxes ); |
|
51 mailClient->GetMailboxesL( mailboxes ); |
|
52 for ( TInt i=0;i<mailboxes.Count(); i++) |
|
53 { |
|
54 MEmailMailbox* mailbox = mailboxes[i]; |
|
55 MEmailMessage* message = mailbox->CreateDraftMessageL(); |
|
56 CleanupReleasePushL( *message ); |
|
57 MEmailAddress* replyto = message->ReplyToAddressL(); |
|
58 if (replyto) |
|
59 { |
|
60 iLog->Log( _L( "reply-to: %S %S" ), &replyto->DisplayName(), replyto->Address()); |
|
61 } |
|
62 REmailAddressArray array; |
|
63 CleanupResetAndRelease<MEmailAddress>::PushL( array ); |
|
64 CEmailInterfaceFactory* factory = CEmailInterfaceFactory::NewL(); |
|
65 CleanupStack::PushL( factory ); |
|
66 MEmailAddress* address = static_cast<MEmailAddress*>( |
|
67 factory->InterfaceL( KEmailIFUidAddress ) ); |
|
68 CleanupReleasePushL( *address ); |
|
69 |
|
70 address->SetAddressL( _L("abc.sender@xyz.com") ); |
|
71 address->SetDisplayNameL( _L("Abc Sender") ); |
|
72 message->SetReplyToAddressL(*address); |
|
73 address->SetAddressL( _L("etu.suku@domain.fi") ); |
|
74 address->SetDisplayNameL( _L("Etu Suku") ); |
|
75 array.Append( address ); |
|
76 message->SetRecipientsL( MEmailAddress::ETo, array ); |
|
77 CleanupStack::PopAndDestroy(); // address |
|
78 message->SetFlag( EFlag_Important ); |
|
79 message->SetSubjectL( _L("Overlook by night") ); |
|
80 message->SetPlainTextBodyL( _L("Here's Johnny!") ); |
|
81 message->SaveChangesL(); |
|
82 iLog->Log( _L( "%S id=%d " ),&mailbox>MailboxName(), |
|
83 mailbox->MailboxId().iId); |
|
84 iLog->Log( _L( "msgid=%d folderid=%d" ), |
|
85 message->MessageId(), |
|
86 message->ParentFolderId() ); |
|
87 message->Flags() ); //Message Flags |
|
88 REmailAddressArray array2; |
|
89 CleanupResetAndRelease<MEmailAddress>::PushL( array2 ); |
|
90 TInt count = message->GetRecipientsL( MEmailAddress::EUndefined, array2 ); |
|
91 iLog->Log( _L( "recipient count= %d" ), count); |
|
92 for (TInt i = 0; i < count; i++) |
|
93 { |
|
94 iLog->Log( _L( "recipient %S %S, role %d" ), &array2[i]->DisplayName(), &array2[i]->Address(), array2[i]->Role()); |
|
95 } |
|
96 MEmailAddress* reply = message->ReplyToAddressL(); |
|
97 iLog->Log( _L( "reply-to: %S %S" ), &reply->DisplayName(), &reply->Address()); |
|
98 /* remove the last recipient */ |
|
99 message->RemoveRecipientL(*array2[count-1]); |
|
100 CleanupStack::PopAndDestroy(); // array2 |
|
101 CleanupResetAndRelease<MEmailAddress>::PushL( array2 ); |
|
102 TInt respcount = message->GetRecipientsL( MEmailAddress::EUndefined, array2 ); |
|
103 iLog->Log( _L( "recipient count= %d" ), respcount); |
|
104 |
|
105 for (TInt i = 0; i < respcount; i++) |
|
106 { |
|
107 iLog->Log( _L( "recipient %S %S, role %d" ), &array2[i]->DisplayName(), &array2[i]->Address(), array2[i]->Role()); |
|
108 } |
|
109 message->SaveChangesL(); |
|
110 CleanupStack::PopAndDestroy(4); // message, array, factory, array2 |
|
111 } |
|
112 CleanupStack::PopAndDestroy( 3 ); // mailboxes, mailclient, factory |
|
113 iLog->Log( _L( "CreateDraftMessageL ends ret=%d" ), ret ); |
|
114 return ret; |
|
115 } |
|
116 </codeblock></p></example> |
|
117 </taskbody><related-links> |
|
118 <link href="GUID-B87B9E01-F5EB-40F6-A580-A7E46869AE39.dita"><linktext>Email Client |
|
119 API Overview</linktext></link> |
|
120 <link href="GUID-1DCB0B64-0B70-4F34-81A7-E00A996AD626.dita"><linktext>Listing, |
|
121 Accessing and Launching Mailboxes</linktext></link> |
|
122 <link href="GUID-222C2B18-F348-4B16-BB00-E5FAC11AE528.dita"><linktext>Searching |
|
123 Email Messages</linktext></link> |
|
124 </related-links></task> |