다음을 통해 공유


Setting OOF Messages (Exchange Web Services)

Topic Last Modified: 2007-09-14

You can use Exchange Web Services to set Out of Office (OOF) messages for a mailbox.

Example

The following code example shows you how to set the OOF message and settings for a user.

static void SetOOF()
{
    // Identify the service and the user.
    ExchangeServiceBinding service = new ExchangeServiceBinding();
    service.Credentials = new NetworkCredential("UserName", "PassWord", "Domain");
    service.Url = @"http://exchangeserver.example.com/EWS/Exchange.asmx";

    // Identify the user mailbox for which to set OOF information.
    EmailAddress emailAddress = new EmailAddress();

    emailAddress.Address = "donhall@example.com";
    emailAddress.Name = String.Empty;

    UserOofSettings OOFSettings = new UserOofSettings();

    // Identify the time that a user is OOF 
    Duration duration = new Duration();
    duration.StartTime = DateTime.Now;
    duration.EndTime = DateTime.Now.AddHours(4);
    OOFSettings.Duration = duration;

    // Identify the external audience.
    OOFSettings.ExternalAudience = ExternalAudience.Known;

    // Create the reply messages.
    ReplyBody internalReply = new ReplyBody();
    ReplyBody externalReply = new ReplyBody();
    externalReply.Message = "This is my external OOF reply";
    internalReply.Message = "This is my internal OOF reply";

    OOFSettings.ExternalReply = externalReply;
    OOFSettings.InternalReply = internalReply;

    // Set OOF state.
    OOFSettings.OofState = OofState.Enabled;

    // Create the request.
    SetUserOofSettingsRequest request = new SetUserOofSettingsRequest();
    request.Mailbox = emailAddress;
    request.UserOofSettings = OOFSettings;

    try
    {
        // Send the request and return the response.
        SetUserOofSettingsResponse response = service.SetUserOofSettings(request);
    }
    catch (Exception e)
    {
        Console.WriteLine(e.Message);
    }
}

The SOAP messages that are passed between the Exchange Web Services client and server are defined by the XML schema and WSDL files. The XML schema and WSDL files define the contract between the client and server. Proxy class generators create an object-model abstraction of those SOAP messages, which can simplify programming. This code example uses a proxy class library that was generated by Microsoft Visual Studio 2005. Different proxy class generators create different object models for a given Web service. This proxy class code example is an illustration only. Refer to the proxy class generator documentation for support for proxy classes.

Compiling the Code

For information about compiling the code, see Exchange Web Services Client Development.