Wednesday, June 09, 2004

Setting OOF status and Text using a OWA Script

I created this blog entry a couple of days ago about using the Microsoft.XMLHTTP to do some automation scripting with exchange in regards to adding entries into the junk email whit lists. This same method can also be used to set a variety of other settings as well, one of these is a user OOF ( Out of office ) setting. You can also set this via a script using CDO 1.2 and also via Exoledb/WebDAV but this does offer a simple alternative. To set the OOF setting of a user you just issue the following commands

OofReply=Im Out of the Office

An example of using this in a script would be

szXml = ""
szXml = szXml & "Cmd=options" & vbLf
szXml = szXml & "OofReply=Im Out of the Office" & vbLf
szXml = szXml & "OofState=1" & vbLf

Set oXmlHttp = CreateObject("Microsoft.XMLHTTP")
oXmlHttp.Open "POST", "http://youserver/exchange/youruser/", False, "", ""
oXmlHttp.setRequestHeader "Accept-Language:", "en-us"
oXmlHttp.setRequestHeader "Content-type:", "application/x-www-UTF8-encoded"
oXmlHttp.setRequestHeader "Content-Length:", Len(szXml)
oXmlHttp.Send szXml

Wscript.echo oXmlHttp.responseText


Anonymous said...

how would you retrieve the oof state and message if you wanted to view it?

Anonymous said...

Great stuff you are posting! Thanks! I am too interested in retrieiving the OOF status for a web app I am developing. Do you know if any .NET compatible APIs for doing something like this?


Glen said...

You can use WebDAV in C# to do this you can get the OOF status using the property (eg via a propfind on the root of the mailbox). Getting the text of the oof message is a little bit more cumbersome becuase you have to first search for the rule message object in the mailbox and then extract the oof text from the body of the message it just involves 2 transaction instead of one.

The one thing to remember is security if you try to access the oof state via a normal mailbox access method then you will need to have full rights on every mailbox to do this. If you go via the adminstrative virtual root then you can get away with delegated exchange admin rights. The other way if you are just after the oof status and not the oof message is to check the free busy information for a user which will tell you also if a user has set thier oof on. see

Anonymous said...

Setting the OOF message works fine this way, but for "enters" in the OOF message.

Is there a way to escape the carriage return and line feed?

It's a little late (2 years after posting the message). But I hope you can answer my question.


Glen said...
This comment has been removed by a blog administrator.
Glen said...

Because the content type is being setup to UTF8 you need to use the escape method for UTF8 in XML which is 
(13 being the decimal value of carriage return)

szXml = szXml & "OofReply=Im Out of the Office 
Next Line" & vbLf


Black said...

I am able to set the OoO state and text, but the response comes back "Bad Request (Invalid Verb)" against an Exchange 2003 server. Do I need to change the POST verb to something else?


Glen said...

POST should work okay eg if you sniff what OWA is doing you should see the same thing. It sounds like you may have an issue with the formating of you code have a look at which describes the verb error your getting

Anonymous said...

Glen I have set-up the cehck free/busy status as here

however it does not seem to check whether the out of office is actually switched on or not, it only displays the calendar details. any ideas why this is?

Glen said...

Thats to be expected the Calendar FreeBusy only show the OOF status of an actually appointment.