Export (0) Print
Expand All
1 out of 2 rated this helpful - Rate this topic

Setting OOF Messages

Exchange Server 2010

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

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

static void SetOOF(ExchangeServiceBinding service)
{
    // 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 MicrosoftVisual 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.

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

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.