Partager via


Forwarding and replying to meeting invitations by using the EWS Managed API 2.0

Last modified: October 13, 2012

Applies to: EWS Managed API | Exchange Server 2007 Service Pack 1 (SP1) | Exchange Server 2010

Note: This content applies to the EWS Managed API 2.0 and earlier versions. For the latest information about the EWS Managed API, see Web services in Exchange.

You can use the Microsoft Exchange Web Services (EWS) Managed API to forward or reply to meeting invitations. Replying to a meeting invitation does not accept, tentatively accept, or decline a meeting invitation; it just sends an e-mail message to the organizer or to the organizer and all attendees. For information about how to accept, tentatively accept, or decline a meeting invitation, see Responding to meeting invitations by using the EWS Managed API 2.0.

Note

When you forward or reply to a meeting invitation, you can forward or reply to either the meeting request message or its associated calendar item.

To forward a meeting invitation

  1. Bind to an existing meeting request message or its associated calendar item by using its unique identifier. The following code shows how to bind to an existing meeting request message and provide it with connection configuration information by using an ExchangeService object named service. The ItemId has been shortened to preserve readability.

    Appointment appointment = Appointment.Bind(service, new ItemId("AAMkA="));
    
  2. Forward the meeting invitation by using either the Forward method or the CreateForward method. Use the Forward method if you want to customize only the MessageBody property on the forwarded meeting invitation. Use the CreateForward method if you want to customize multiple properties on the forwarded meeting invitation.

    • The following code shows how to forward a meeting invitation to two e-mail addresses by using the Forward method. The first parameter in the Forward method call specifies the custom text that will be prepended to the MessageBody property on the forwarded meeting invitation.

      EmailAddress[] fwdAddresses = new EmailAddress[2];
      fwdAddresses[0] = new EmailAddress("user1@contoso.com");
      fwdAddresses[1] = new EmailAddress("user2@contoso.com");
      appointment.Forward("I'm sharing this meeting invitation with you because I thought you might want to attend.", fwdAddresses);
      
    • The following code shows how to forward a meeting invitation to two e-mail addresses by using the CreateForward method. The code customizes the MessageBody property on the forwarded meeting invitation and requests a delivery receipt.

      ResponseMessage fwdMessage = appointment.CreateForward();
      fwdMessage.ToRecipients.Add("user1@contoso.com");
      fwdMessage.ToRecipients.Add("user2@contoso.com");
      fwdMessage.BodyPrefix = "I'm sharing this meeting invitation with you because I thought you might want to attend.";
      fwdMessage.IsDeliveryReceiptRequested = true;
      fwdMessage.SendAndSaveCopy();
      

To reply to a meeting invitation

  1. Bind to an existing meeting request message or to its associated calendar item by using its unique identifier. The following code shows how to bind to an existing meeting request message and provide it with connection configuration information by using an ExchangeService object named service. The ItemId has been shortened to preserve readability.

    Appointment appointment = Appointment.Bind(service, new ItemId("AAMkA="));
    
  2. Reply to the meeting invitation by using either the Reply method or the CreateReply method. Use the Reply method if you want to customize only the MessageBody property on the meeting invitation reply message. Use the CreateReply method if you want to customize multiple properties on the meeting invitation reply message.

    • The following code shows how to create a meeting invitation reply message and send the reply message to only the meeting organizer by using the Reply method. To send the reply message to the meeting organizer and all attendees, set the second parameter value to true instead of false.

      appointment.Reply("Do I need my laptop for this meeting?", false);
      
    • The following code shows how to create a meeting invitation reply message and send the reply message to only the meeting organizer by using the CreateReply method. To send the reply message to the meeting organizer and all attendees, set the parameter value to true instead of false when calling the CreateReply method. The code customizes the MessageBody property on the meeting invitation reply message and requests a read receipt.

      ResponseMessage replyMessage = appointment.CreateReply(false);
      replyMessage.Body = new MessageBody("Do I need my laptop for this meeting?");
      replyMessage.IsReadReceiptRequested = true;
      replyMessage.SendAndSaveCopy();
      

Example

Forwarding a meeting invitation

The following code example shows how to forward a meeting request message to two recipients by using the Forward method. A copy of the message is saved in the Sent Items folder. This example assumes that service is a valid ExchangeService binding. The ItemId has been shortened to preserve readability.

// Bind to the meeting request message by using its unique identifier.
Appointment appointment = Appointment.Bind(service, new ItemId("AAMkA="));

// Specify the recipient e-mail addresses and forward the meeting request message to the recipients with customized message body text. 
EmailAddress[] fwdAddresses = new EmailAddress[2];
fwdAddresses[0] = new EmailAddress("user1@contoso..com");
fwdAddresses[1] = new EmailAddress("user2@contoso.com");
appointment.Forward("I'm sharing this meeting invitation with you because I thought you might want to attend.", fwdAddresses);

The following example shows the XML that is sent by using the Forward method. The ItemId and ChangeKey attributes have been shortened to preserve readability.

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
               xmlns:m="https://schemas.microsoft.com/exchange/services/2006/messages" 
               xmlns:t="https://schemas.microsoft.com/exchange/services/2006/types" 
               xmlns:soap="https://schemas.xmlsoap.org/soap/envelope/">
   <soap:Header>
      <t:RequestServerVersion Version="Exchange2010" />
   </soap:Header>
   <soap:Body>
      <m:CreateItem MessageDisposition="SendAndSaveCopy">
         <m:Items>
            <t:ForwardItem>
               <t:ToRecipients>
                  <t:Mailbox>
                     <t:EmailAddress>user1@contoso.com</t:EmailAddress>
                  </t:Mailbox>
                  <t:Mailbox>
                     <t:EmailAddress>user2@contoso.com</t:EmailAddress>
                  </t:Mailbox>
               </t:ToRecipients>
               <t:ReferenceItemId Id="AQMkA" ChangeKey="DwAAA" />
               <t:NewBodyContent BodyType="Text">I'm sharing this meeting invitation with you because I thought you might want to attend.</t:NewBodyContent>
            </t:ForwardItem>
         </m:Items>
      </m:CreateItem>
   </soap:Body>
</soap:Envelope>

The following example shows the XML that is returned by using the Forward method.

<?xml version="1.0" encoding="utf-8"?>
<s:Envelope xmlns:s="https://schemas.xmlsoap.org/soap/envelope/">
   <s:Header>
      <h:ServerVersionInfo MajorVersion="14" MinorVersion="0" MajorBuildNumber="478" MinorBuildNumber="0" Version="Exchange2010" 
         xmlns:h="https://schemas.microsoft.com/exchange/services/2006/types" 
         xmlns="https://schemas.microsoft.com/exchange/services/2006/types" 
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
         xmlns:xsd="http://www.w3.org/2001/XMLSchema" />
   </s:Header>
   <s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
      <m:CreateItemResponse xmlns:m="https://schemas.microsoft.com/exchange/services/2006/messages" xmlns:t="https://schemas.microsoft.com/exchange/services/2006/types">
         <m:ResponseMessages>
            <m:CreateItemResponseMessage ResponseClass="Success">
               <m:ResponseCode>NoError</m:ResponseCode>
               <m:Items />
            </m:CreateItemResponseMessage>
         </m:ResponseMessages>
      </m:CreateItemResponse>
   </s:Body>
</s:Envelope>

Replying to a meeting invitation

The following code example shows how to create a reply message by using the CreateReply method and send the reply message to the meeting organizer and to all attendees by using the SendAndSaveCopy method. A copy of the message is saved in the Sent Items folder. This example assumes that service is a valid ExchangeService binding. The ItemId has been shortened to preserve readability.

// Bind to the meeting request message by using its unique identifier.
Appointment appointment = Appointment.Bind(service, new ItemId("AAMkA="));

// Create the reply message (to be sent to the meeting organizer and all attendees), customize the the message body text, and set an additional property.
ResponseMessage replyMessage = appointment.CreateReply(true);
replyMessage.Body = new MessageBody("Do I need my laptop for this meeting?");
replyMessage.IsReadReceiptRequested = true;

// Send the reply message and save a copy in the Sent Items folder.
replyMessage.SendAndSaveCopy();

The following example shows the XML that is sent by using the CreateReply method and the SendAndSaveCopy method. The ItemId and ChangeKey attributes have been shortened to preserve readability.

<?xml version="1.0" encoding="utf-8"?>
   <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
                  xmlns:m="https://schemas.microsoft.com/exchange/services/2006/messages" 
                  xmlns:t="https://schemas.microsoft.com/exchange/services/2006/types" 
                  xmlns:soap="https://schemas.xmlsoap.org/soap/envelope/">
   <soap:Header>
      <t:RequestServerVersion Version="Exchange2010" />
   </soap:Header>
   <soap:Body>
      <m:CreateItem MessageDisposition="SendAndSaveCopy">
         <m:Items>
            <t:ReplyAllToItem>
               <t:Body BodyType="Text">Do I need my laptop for this meeting?</t:Body>
               <t:IsReadReceiptRequested>true</t:IsReadReceiptRequested>
               <t:ReferenceItemId Id="AQMkA" ChangeKey="DwAAA" />
            </t:ReplyAllToItem>
         </m:Items>
      </m:CreateItem>
   </soap:Body>
</soap:Envelope>

The following example shows the XML that is returned by using the CreateReply method and the SendAndSaveCopy method.

<?xml version="1.0" encoding="utf-8"?>
<s:Envelope xmlns:s="https://schemas.xmlsoap.org/soap/envelope/">
   <s:Header>
      <h:ServerVersionInfo MajorVersion="14" MinorVersion="0" MajorBuildNumber="478" MinorBuildNumber="0" Version="Exchange2010" 
         xmlns:h="https://schemas.microsoft.com/exchange/services/2006/types" 
         xmlns="https://schemas.microsoft.com/exchange/services/2006/types" 
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
         xmlns:xsd="http://www.w3.org/2001/XMLSchema" />
   </s:Header>
   <s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
      <m:CreateItemResponse xmlns:m="https://schemas.microsoft.com/exchange/services/2006/messages" xmlns:t="https://schemas.microsoft.com/exchange/services/2006/types">
         <m:ResponseMessages>
            <m:CreateItemResponseMessage ResponseClass="Success">
               <m:ResponseCode>NoError</m:ResponseCode>
               <m:Items />
            </m:CreateItemResponseMessage>
         </m:ResponseMessages>
      </m:CreateItemResponse>
   </s:Body>
</s:Envelope>

Compiling the code

For information about compiling this code, see Getting started with the EWS Managed API 2.0.

Robust programming

  • Write appropriate error handling code for common search errors.

  • Review the client request XML that is sent to the Exchange server.

  • Review the server response XML that is sent from the Exchange server.

  • Set the service binding as shown in Setting the Exchange service URL by using the EWS Managed API 2.0. Do not hard code URLs because if mailboxes move, they might be serviced by a different Client Access server. If the client cannot connect to the service, retry setting the binding by using the AutodiscoverUrl(String) method.

  • Set the target Exchange Web Services schema version by setting the requestedServerVersion parameter of the ExchangeService constructor. For more information, see Versioning EWS requests by using the EWS Managed API 2.0.

Security

  • Use HTTP with SSL for all communication between client and server.

  • Always validate the server certificate that is used for establishing the SSL connections. For more information, see Validating X509 certificates by using the EWS Managed API 2.0.

  • Do not include user names and passwords in trace files.

  • Verify that Autodiscover lookups that use HTTP GET to find an endpoint always prompt for user confirmation; otherwise, they should be blocked.