Responding 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 accept, tentatively accept, or decline meeting invitations.

Note

When you respond to a meeting invitation, you can respond to either the meeting request message or its associated calendar item. In either case, Exchange Web Services will apply changes to both the meeting request message and the associated calendar item. Exchange Web Services does, however, delete and re-create the associated calendar item every time that you submit a meeting response, which means that the new associated calendar item will have a different Id.

To accept 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. Accept the meeting invitation by using either the Accept method or the CreateAcceptMessage method. Use the Accept method if you want to send a non-customized acceptance response to the meeting organizer. Use the CreateAcceptMessage method if you want to send a customized acceptance response to the meeting organizer.

    • The following code shows how to accept a meeting invitation and send the response to the meeting organizer by using the Accept method. To accept a meeting invitation without sending the response to the meeting organizer, set the parameter value to false instead of true.

      appointment.Accept(true);
      
    • The following code shows how to accept a meeting invitation and send a customized acceptance response to the organizer by using the CreateAcceptMessage method. The acceptance message contains customized body text and is marked Private.

      AcceptMeetingInvitationMessage acceptMessage = appointment.CreateAcceptMessage(false);
      acceptMessage.Body = new MessageBody("I have another meeting immediately preceding this one, so I may arrive a few minutes late.");
      acceptMessage.Sensitivity = Sensitivity.Private;
      acceptMessage.Send();
      

To tentatively accept 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. Tentatively accept the meeting invitation by using either the AcceptTentatively method or the CreateAcceptMessage method. Use the AcceptTentatively method if you want to send a non-customized tentative acceptance response to the meeting organizer. Use the CreateAcceptMessage method if you want to send a customized tentative acceptance response to the meeting organizer.

    • The following code shows how to tentatively accept a meeting invitation and send the response to the meeting organizer by using the AcceptTentatively method. To tentatively accept a meeting invitation without sending the response to the meeting organizer, set the parameter value to false instead of true.

      appointment.AcceptTentatively(true);
      
    • The following code shows how to tentatively accept a meeting invitation and send a customized tentative acceptance response to the organizer by using the CreateAcceptMessage method. The tentative acceptance message contains customized body text and is marked Private.

      AcceptMeetingInvitationMessage tentativelyAcceptMessage = appointment.CreateAcceptMessage(true);
      tentativelyAcceptMessage.Body = new MessageBody("I have another meeting immediately preceding this one. If it runs late, I may miss your meeting altogether.");
      tentativelyAcceptMessage.Sensitivity = Sensitivity.Private;
      tentativelyAcceptMessage.Send();
      

To decline a meeting invitation

  1. Bind to an existing meeting request message by using its unique identifier 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. Decline the meeting invitation by either using the Decline method or by using the CreateDeclineMessage method. Use the Decline method if you want to send a non-customized decline response to the meeting organizer. Use the CreateDeclineMessage method if you want to send a customized decline response to the meeting organizer.

    • The following code shows how to decline a meeting invitation and send the response to the meeting organizer by using the Decline method. To decline a meeting invitation without sending the response to the meeting organizer, set the parameter value to false instead of true.

      appointment.Decline(true);
      
    • The following code shows how to decline a meeting invitation and send a customized decline response to the organizer by using the CreateDeclineMessage method. The decline message contains customized body text and is marked Private.

      DeclineMeetingInvitationMessage declineMessage = appointment.CreateDeclineMessage();
      declineMessage.Body = new MessageBody("I will not be able to attend because I have a conflicting meeting at this time.");
      declineMessage.Sensitivity = Sensitivity.Private;
      declineMessage.Send();
      

Example

Accepting a meeting invitation

The following code example shows how to accept a meeting invitation and send a customized acceptance response to the meeting organizer. The acceptance message contains customized body text and is marked Private. 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="));

// Accept the meeting invitation and send a customized acceptance message to the meeting organizer.
AcceptMeetingInvitationMessage acceptMessage = appointment.CreateAcceptMessage(false);
acceptMessage.Body = new MessageBody("I have another meeting immediately preceding this one, so I may arrive a few minutes late.");
acceptMessage.Sensitivity = Sensitivity.Private;
acceptMessage.Send();

The following example shows the XML that is sent by using the Send method. The ReferenceItemId element contains the unique identifier and change key of the meeting request message that was bound to by using the Bind 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="SendOnly">
         <m:Items>
            <t:AcceptItem>
               <t:Sensitivity>Private</t:Sensitivity>
               <t:Body BodyType="Text">I have another meeting immediately preceding this one, so I may arrive a few minutes late.</t:Body>
               <t:ReferenceItemId Id="AQMkA" ChangeKey="DwAAA" />
            </t:AcceptItem>
         </m:Items>
      </m:CreateItem>
   </soap:Body>
</soap:Envelope>

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

<?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>
                  <t:CalendarItem>
                     <t:ItemId Id="AQMkA" ChangeKey="DwAAA" />
                  </t:CalendarItem>
               </m:Items>
            </m:CreateItemResponseMessage>
         </m:ResponseMessages>
      </m:CreateItemResponse>
   </s:Body>
</s:Envelope>

Tentatively accepting a meeting invitation

The following code example shows how to tentatively accept a meeting invitation and send a non-customized tentative acceptance response to the meeting organizer. 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="));

// Tentatively accept the meeting invitation and send a non-customized tentative acceptance response to the meeting organizer.
appointment.AcceptTentatively(true);

The following example shows the XML that is sent by using the AcceptTentatively method. The ReferenceItemId element contains the unique identifier and change key of the meeting request message that was bound to by using the Bind 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:TentativelyAcceptItem>
               <t:ReferenceItemId Id="AQMkA" ChangeKey="DwAAA" />
            </t:TentativelyAcceptItem>
         </m:Items>
      </m:CreateItem>
   </soap:Body>
</soap:Envelope>

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

<?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>
                  <t:CalendarItem>
                     <t:ItemId Id="AQMkA" ChangeKey="DwAAA" />
                  </t:CalendarItem>
               </m:Items>
            </m:CreateItemResponseMessage>
         </m:ResponseMessages>
      </m:CreateItemResponse>
   </s:Body>
</s:Envelope>

Declining a meeting invitation

The following code example shows how to decline a meeting invitation and send a customized decline response to the meeting organizer. The decline message contains customized body text and is marked Private. 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="));

// Decline the meeting invitation and send a customized decline message to the meeting organizer.
DeclineMeetingInvitationMessage declineMessage = appointment.CreateDeclineMessage();
declineMessage.Body = new MessageBody("I will not be able to attend because I have a conflicting meeting at this time.");
declineMessage.Sensitivity = Sensitivity.Private;
declineMessage.Send();

The following example shows the XML that is sent by using the Send method. The ReferenceItemId element contains the unique identifier and change key of the meeting request message that was bound to by using the Bind 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="SendOnly ">
         <m:Items>
            <t:DeclineItem>
               <t:Sensitivity>Private</t:Sensitivity>
               <t:Body BodyType="Text">I will not be able to attend because I have a conflicting meeting at this time.</t:Body>
               <t:ReferenceItemId Id="AQMkA" ChangeKey="DwAAA" />
            </t:DeclineItem>
         </m:Items>
      </m:CreateItem>
   </soap:Body>
</soap:Envelope>

The following example shows the XML that is returned by using the Send 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.