Jaa


Getting automatic reply information by using the EWS Managed API 2.0

You can use the Microsoft Exchange Web Services (EWS) Managed API to retrieve settings information for automatic replies, such as Out of Office (OOF) messages, for an email client.

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.

To get automatic reply settings information

  1. Instantiate the OofSettings object.

    OofSettings myOOF = new OofSettings();
    
  2. Get the properties that are set on the OofSettings object and identify the Exchange service. The following example shows how to retrieve OOF state information by using an ExchangeService object named service.

    // Return the Out Of Office object that contains OOF state. This method will result in a call to the Exchange server.
    OofSettings myOOFSettings = service.GetUserOofSettings("user1@contoso.com");
    
  3. Get the individual property values. The following example assigns the retrieved values to local variables.

    // Get the (read-only) audience of email message senders outside a client's organization who will receive automatic replies (All/Known/None).
    OofExternalAudience myAllowedExternalAudience = myOOF.AllowExternalOof;
    
    // Get the duration for a scheduled automatic reply.
    TimeWindow myOOFDuration = myOOF.Duration;
    
    // Get the ExternalAudience of email message senders outside a client's organization who will receive automatic automatic replies (All/Known/None).
    OofExternalAudience myExternalAudience = myOOF.ExternalAudience;
    
    // Get the reply to be sent to email message senders outside a client's organization.
    OofReply myExternalReply = myOOF.ExternalReply;
    
    // Get the reply to be sent to email message senders inside a client's organization.
    OofReply myInternalReply = myOOF.InternalReply;
    
    // Get the (Disabled/Enabled/Scheduled) state of the Automatic Replies (Out of Office) feature.
    OofState myOofState = myOOF.State;
    

Example

The following example shows how to return and display automatic reply information.

static void GetOOF(ExchangeService service)
{
    OofSettings myOOF = new OofSettings();

    // Return the Out Of Office object that contains OOF state. This method will result in a call to the Exchange Server.
    OofSettings myOOFSettings = service.GetUserOofSettings("someone@example.com");

    // Get the (read-only) audience of email message senders outside a client's organization who will receive automatic Out Of Office replies ("All", "Known", or "None").
    OofExternalAudience myAllowedExternalAudience = myOOF.AllowExternalOof;

    // Get the duration for a scheduled Out Of Office reply.
    TimeWindow myOOFDuration = myOOF.Duration;

    // Get the ExternalAudience of email message senders outside a client's organization who will receive automatic Out OF Office replies (All/Known/None).
    OofExternalAudience myExternalAudience = myOOF.ExternalAudience;
    
    // Get the reply to be sent to email message senders outside a client's organization.
    OofReply myExternalReply = myOOF.ExternalReply;

    // Get the reply to be sent to email message senders inside a client's organization.
    OofReply myInternalReply = myOOF.InternalReply;

    // Get the (Disabled/Enabled/Scheduled) state of the Out Of Office automatic reply feature.
    OofState myOofState = myOOF.State;
}

The following example shows the XML that is sent by using the GetUserOofSettings method.

<?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_SP1" />
    </soap:Header>
    <soap:Body>
      <m:GetUserOofSettingsRequest>
        <t:Mailbox>
          <t:Address>user1@contoso.com</t:Address>
        </t:Mailbox>
      </m:GetUserOofSettingsRequest>
    </soap:Body>
  </soap:Envelope>

The following example shows the XML that is returned by the GetUserOofSettings 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="15" MajorBuildNumber="3" MinorBuildNumber="0" Version="Exchange2010_SP2" 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">
      <GetUserOofSettingsResponse xmlns="https://schemas.microsoft.com/exchange/services/2006/messages">
        <ResponseMessage ResponseClass="Success">
          <ResponseCode>NoError</ResponseCode>
        </ResponseMessage>
        <OofSettings xmlns="https://schemas.microsoft.com/exchange/services/2006/types">
          <OofState>Disabled</OofState>
          <ExternalAudience>All</ExternalAudience>
          <Duration>
            <StartTime>2011-10-25T04:00:00Z</StartTime>
            <EndTime>2011-10-26T04:00:00Z</EndTime>
          </Duration>
          <InternalReply xml:lang="en-us">
            <Message>?&lt;html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="https://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"&gt;&lt;head&gt;&lt;meta http-equiv=Content-Type content="text/html; charset=unicode"&gt;&lt;meta name=Generator content="Microsoft Word 14 (filtered medium)"&gt;&lt;style&gt;&lt;!--
/* Font Definitions */
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri","sans-serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
span.EmailStyle17
        {mso-style-type:personal-compose;
        font-family:"Times New Roman","serif";}
.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri","sans-serif";}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--&gt;&lt;/style&gt;&lt;/head&gt;&lt;body lang=EN-US link=blue vlink=purple&gt;&lt;div class=WordSection1&gt;&lt;p class=MsoNormal style='text-autospace:none'&gt;&lt;span style='font-size:12.0pt;font-family:"Times New Roman","serif"'&gt;I'm currently out of office. Please contact my manager ThomR for critical issues. Thanks!&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;/body&gt;&lt;/html&gt;</Message>
          </InternalReply>
          <ExternalReply xml:lang="en-us">
            <Message>?&lt;html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="https://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"&gt;&lt;head&gt;&lt;meta http-equiv=Content-Type content="text/html; charset=unicode"&gt;&lt;meta name=Generator content="Microsoft Word 14 (filtered medium)"&gt;&lt;style&gt;&lt;!--
/* Font Definitions */
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri","sans-serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
span.EmailStyle17
        {mso-style-type:personal-compose;
        font-family:"Times New Roman","serif";}
.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri","sans-serif";}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--&gt;&lt;/style&gt;&lt;/head&gt;&lt;body lang=EN-US link=blue vlink=purple&gt;&lt;div class=WordSection1&gt;&lt;p class=MsoNormal style='text-autospace:none'&gt;&lt;span style='font-size:12.0pt;font-family:"Times New Roman","serif"'&gt;I am currently out of the office but will reply to emails when I return. Thanks!&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;/body&gt;&lt;/html&gt
;</Message>
          </ExternalReply>
        </OofSettings>
        <AllowExternalOof>All</AllowExternalOof>
      </GetUserOofSettingsResponse>
    </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.