HOWTO: EWS: Disable Out-of-office / OOF message
WebDav is definitely de-emphasized and not recommended to develop applications for Exchange 2007. But WebDav was still the easiest method to disable OOF message. I was not surprised to see it NOT working against Exchange 2007 to disable the OOF message. I have a better solution for you… use my favorite technology, Exchange Web Services!!!
using System;
using System.Collections.Generic;
using System.Text;
using DisableOof.MyEWS;
namespace DisableOof
{
class Program
{
//TODO: Add Web Reference to your Exchange 2007 WebService URI
//default URI is https://Your-Cas-Server/EWS/Exchange.asmx
//
//Refrences:
// Configuring Exchange Impersonation
// https://msdn2.microsoft.com/en-us/library/bb204095.aspx
const string sUrl = "https://Your-Cas-Server/EWS/Exchange.asmx"; //TODO: Exchange 2007 WebService URI
const string sUsr = "Username"; //TODO: Username for the user that has service account level
const string sPwd = "Password"; //TODO: Password
const string sDom = "DOMAIN"; //TODO: Your Exchange Domain Name
const string sMyEmailAddress = "myusername@domain.com";
//Email address for the user to impersonate
const string sImpersonatedUserEmail = "Impersonated-User@domain.com";
static void Main(string[] args)
{
ExchangeServiceBinding esb = new ExchangeServiceBinding();
esb.AllowAutoRedirect = true;
esb.Url = sUrl;
esb.Credentials = new System.Net.NetworkCredential(sUsr, sPwd, sDom);
esb.UnsafeAuthenticatedConnectionSharing = true;
//////Impersonate user and Disable OOF entries for impersonated user
//////Uncomment this to enable impersonation
//////See references on top to configure impersonation on exchange 2007
//////
////esb.ExchangeImpersonation = new ExchangeImpersonationType();
////esb.ExchangeImpersonation.ConnectingSID = new ConnectingSIDType();
////esb.ExchangeImpersonation.ConnectingSID.PrimarySmtpAddress = sImpersonatedUserEmail;
EmailAddress email = new EmailAddress();
if (null == esb.ExchangeImpersonation)
email.Address = sMyEmailAddress;
else
email.Address = sImpersonatedUserEmail;
if (DisableOOF(esb, email))
Console.WriteLine("Success: OOF Disabled");
else
Console.WriteLine("Error: Could not disable Oof Settings");
}
public static bool DisableOOF(ExchangeServiceBinding esb, EmailAddress emailAddress)
{
SetUserOofSettingsRequest request = new SetUserOofSettingsRequest();
request.UserOofSettings = new UserOofSettings();
request.UserOofSettings.OofState = OofState.Disabled;
request.UserOofSettings.ExternalAudience = ExternalAudience.All;
request.UserOofSettings.ExternalReply = new ReplyBody();
request.UserOofSettings.ExternalReply.Message = "";
request.UserOofSettings.InternalReply = new ReplyBody();
request.UserOofSettings.InternalReply.Message = "";
request.Mailbox = emailAddress;
SetUserOofSettingsResponse response = esb.SetUserOofSettings(request);
if (response.ResponseMessage.ResponseClass == ResponseClassType.Success)
return true;
else
return false;
}
}
}
Keywords: SetUserOofSettings, ExchangeImpersonation, Exchange Web Services, Exchange 2007, Out Of Office
Comments
Anonymous
November 19, 2007
PingBack from http://msdnrss.thecoderblogs.com/2007/11/20/howto-ews-disable-out-of-office-oof-message/Anonymous
November 21, 2007
Yes you can consume Exchange Web Service using VBScript or any language / platform which support HTML.Anonymous
November 21, 2007
Yes you can consume Exchange Web Service using VBScript or any language / platform which support HTMLAnonymous
January 17, 2008
HOWTO: EWS: Consume Exchange Web Service from VBScript