Symbian3/PDK/Source/GUID-FC308B84-E109-48F3-90F1-78F0C837CC56.dita
changeset 5 f345bda72bc4
child 9 59758314f811
equal deleted inserted replaced
4:4816d766a08a 5:f345bda72bc4
       
     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-&gt;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-&gt;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-&gt;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&amp; /*aItem*/ )
       
    45 	{
       
    46 		
       
    47 		TInt ret( KErrNone);
       
    48 		MEmailClientApi* mailClient = CreateFactoryAndClientApiLC();
       
    49 		RMailboxPtrArray mailboxes;
       
    50 		CleanupResetAndRelease&lt;MEmailMailbox&gt;::PushL( mailboxes );
       
    51 		mailClient-&gt;GetMailboxesL( mailboxes );
       
    52 		for ( TInt i=0;i&lt;mailboxes.Count(); i++) 
       
    53 			{
       
    54 		    MEmailMailbox* mailbox = mailboxes[i];
       
    55 				MEmailMessage* message = mailbox-&gt;CreateDraftMessageL();
       
    56 				CleanupReleasePushL( *message );
       
    57 	  		MEmailAddress* replyto = message-&gt;ReplyToAddressL();
       
    58 				if (replyto)
       
    59 				{
       
    60 					iLog-&gt;Log( _L( "reply-to: %S %S" ), &amp;replyto-&gt;DisplayName(), replyto-&gt;Address());
       
    61 				}
       
    62 				REmailAddressArray array;
       
    63 				CleanupResetAndRelease&lt;MEmailAddress&gt;::PushL( array );
       
    64 				CEmailInterfaceFactory* factory = CEmailInterfaceFactory::NewL();
       
    65 				CleanupStack::PushL( factory );
       
    66 				MEmailAddress* address = static_cast&lt;MEmailAddress*&gt;(
       
    67 				factory-&gt;InterfaceL( KEmailIFUidAddress ) );        
       
    68 				CleanupReleasePushL( *address );
       
    69          
       
    70 				address-&gt;SetAddressL( _L("abc.sender@xyz.com") );
       
    71 				address-&gt;SetDisplayNameL( _L("Abc Sender") );
       
    72 				message-&gt;SetReplyToAddressL(*address);        
       
    73 				address-&gt;SetAddressL( _L("etu.suku@domain.fi") );
       
    74 				address-&gt;SetDisplayNameL( _L("Etu Suku") );
       
    75 				array.Append( address );
       
    76 				message-&gt;SetRecipientsL( MEmailAddress::ETo, array ); 
       
    77 				CleanupStack::PopAndDestroy(); // address
       
    78 				message-&gt;SetFlag( EFlag_Important );
       
    79 				message-&gt;SetSubjectL( _L("Overlook by night") );
       
    80 				message-&gt;SetPlainTextBodyL( _L("Here's Johnny!") );
       
    81 				message-&gt;SaveChangesL();
       
    82 				iLog-&gt;Log( _L( "%S id=%d " ),&amp;mailbox&gt;MailboxName(),  
       
    83 				mailbox-&gt;MailboxId().iId);
       
    84 				iLog-&gt;Log( _L( "msgid=%d folderid=%d" ), 
       
    85 				message-&gt;MessageId(), 
       
    86 				message-&gt;ParentFolderId() );
       
    87 				message-&gt;Flags() ); //Message Flags
       
    88 				REmailAddressArray array2;
       
    89 				CleanupResetAndRelease&lt;MEmailAddress&gt;::PushL( array2 );
       
    90 				TInt count = message-&gt;GetRecipientsL( MEmailAddress::EUndefined, array2 );
       
    91 				iLog-&gt;Log( _L( "recipient count= %d" ), count);                                   
       
    92 				for (TInt i = 0; i &lt; count; i++)
       
    93 				{
       
    94 					iLog-&gt;Log( _L( "recipient %S %S, role %d" ), &amp;array2[i]-&gt;DisplayName(), &amp;array2[i]-&gt;Address(), array2[i]-&gt;Role());            
       
    95 				}
       
    96 				MEmailAddress* reply = message-&gt;ReplyToAddressL();
       
    97 				iLog-&gt;Log( _L( "reply-to: %S %S" ), &amp;reply-&gt;DisplayName(), &amp;reply-&gt;Address());
       
    98 				/* remove the last recipient */
       
    99 				message-&gt;RemoveRecipientL(*array2[count-1]);        
       
   100 				CleanupStack::PopAndDestroy(); // array2
       
   101 				CleanupResetAndRelease&lt;MEmailAddress&gt;::PushL( array2 );
       
   102 				TInt respcount = message-&gt;GetRecipientsL( MEmailAddress::EUndefined, array2 );
       
   103 				iLog-&gt;Log( _L( "recipient count= %d" ), respcount); 
       
   104                           
       
   105 				for (TInt i = 0; i &lt; respcount; i++)
       
   106 				{
       
   107 				 iLog-&gt;Log( _L( "recipient %S %S, role %d" ), &amp;array2[i]-&gt;DisplayName(), &amp;array2[i]-&gt;Address(), array2[i]-&gt;Role());            
       
   108 				}
       
   109 				message-&gt;SaveChangesL();
       
   110 				CleanupStack::PopAndDestroy(4); // message, array, factory, array2
       
   111 	}    
       
   112 	CleanupStack::PopAndDestroy( 3 ); // mailboxes, mailclient, factory
       
   113 	iLog-&gt;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>