public bool SetUserOOFSettings(string mailAddress, string password, bool isOOF)
{
using (ExchangeServiceBinding service = new ExchangeServiceBinding())
{
service.Url = Common.GetConfigurationPropertyValue(Constants.SetOOFWebServiceURL, this.Site);
if (service.Url.StartsWith("https", StringComparison.OrdinalIgnoreCase))
{
this.AcceptServerCertificate();
}
service.Credentials = new System.Net.NetworkCredential(mailAddress, password);
EmailAddress emailAddress = new EmailAddress
{
Address = mailAddress, Name = string.Empty
};
UserOofSettings userSettings = new UserOofSettings
{
// Identify the external audience.
ExternalAudience = ExternalAudience.Known
};
// Create the OOF reply messages.
ReplyBody replyBody = new ReplyBody
{
Message = Constants.MessageOfOOFReply
};
userSettings.ExternalReply = replyBody;
userSettings.InternalReply = replyBody;
// Set OOF state.
if (isOOF)
{
userSettings.OofState = OofState.Enabled;
}
else
{
userSettings.OofState = OofState.Disabled;
}
// Create the request.
SetUserOofSettingsRequest request = new SetUserOofSettingsRequest
{
Mailbox = emailAddress,
UserOofSettings = userSettings
};
bool success = false;
try
{
SetUserOofSettingsResponse response = service.SetUserOofSettings(request);
if (response.ResponseMessage.ResponseCode == ResponseCodeType.NoError)
{
success = true;
}
}
catch (System.Xml.Schema.XmlSchemaValidationException e)
{
// Catch the following critical exceptions, other unexpected exceptions will be emitted to protocol test framework.
Site.Log.Add(LogEntryKind.Debug, "An XML schema exception happened. The exception type is {0}.\n The exception message is {1}.", e.GetType().ToString(), e.Message);
}
catch (System.Xml.XmlException e)
{
Site.Log.Add(LogEntryKind.Debug, "An XML schema exception happened. The exception type is {0}.\n The exception message is {1}.", e.GetType().ToString(), e.Message);
}
catch (System.Reflection.TargetException e)
{
Site.Log.Add(LogEntryKind.Debug, "An operation exception happened when invoke Soap operation. The exception type is {0}.\n The exception message is {1}.", e.GetType().ToString(), e.Message);
throw;
}
catch (System.IO.IOException e)
{
Site.Log.Add(LogEntryKind.Debug, "An IO exception happened when invoke Soap operation. The exception type is {0}.\n The exception message is {1}.", e.GetType().ToString(), e.Message);
throw;
}
return success;
}
}