I work for an MSP and we have a single mailbox that we use to process incoming email requests into our ticketing system. I have created a VBA script that runs and processes new emails and such. We are using Outlook 2010 (32-bit) and we are running on Office 365 [Exchange 2013].

We now want to automatically enable and disable an Out Of Office message on the mailbox for after hours and holidays. I already have most of the code written to check for any ongoing meetings that would enable and disable the Out of Office when the meetings start / end. This way we can setup a reoccuring meeting everyday at 5pm to turn on the OOF message and at 4am to disable it. This will also work with All Day Events (such as Holidays).

The only issue I am having is setting the actual OOF message to enable/disable and changing the message body. We would like to be able to set the message body based on the

Below are the snippets I have that get the OOF status and to enable/disable OOF based on various searches I have performed. It looks like CDO 1.21 would be the easiest way to go, but Outlook 2010 seems to not support CDO 1.21.

Acquire OOF Status

Private Function QOA_GetOOFStatus()

Dim oNS As Outlook.NameSpace
Dim oStores As Outlook.Stores
Dim oStr As Outlook.Store
Dim oPrp As Outlook.PropertyAccessor
Dim OOFStatus As Boolean

OOFStatus = False

Set oNS = Application.GetNamespace("MAPI")
Set oStores = oNS.Stores

For Each oStr In oStores
    If oStr.ExchangeStoreType = olPrimaryExchangeMailbox Then
        Set oPrp = oStr.PropertyAccessor
        OOFStatus = oPrp.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x661D000B")
    End If
tempValue = OOFStatus

QOA_GetOOFStatus = OOFStatus

End Function

Enable/Disable OOF with body message

Const PR_OOF_STATE = "http://schemas.microsoft.com/mapi/proptag/0x661D000B"

Dim oStore As Outlook.Store, oProp As Outlook.PropertyAccessor
Dim oStorageItem As Outlook.StorageItem

Set oStorageItem = Application.Session.GetDefaultFolder(olFolderInbox).GetStorage("IPM.Note.Rules.OofTemplate.Microsoft", olIdentifyByMessageClass)

oStorageItem.Body = "I am out of the office!"

For Each oStore In Session.Stores
    If oStore.ExchangeStoreType = olPrimaryExchangeMailbox Then

        Set oProp = oStore.PropertyAccessor
        oProp.SetProperty PR_OOF_STATE, True

    End If
Set olkIS = Nothing
Set olkPA = Nothing

I'm guessing there's something to do with the 'Internal' and 'External' OOF replies that are featured in Exchange 2010, 2013.

I'm not opposed to running an external program that set OOF messages.

Any suggestions or thoughts on how I can proceed? I would hate to have to give up when I just need to find the way to disable/enable OOF!

  • isn't it just OutOfOffice True or false? – Raystafarian Jul 23 '13 at 18:31
  • @Raystafarian I'm not quite sure what you mean? – Zach Jul 23 '13 at 19:34
  • Yeah, I think that's old. Since OOO is a rule there is no toggle for on/off, just applying the rule or not. Sorry I couldn't be of better help. – Raystafarian Jul 23 '13 at 20:44

I decided to use EWSOofUtil.dll and create an external powershell script to pass my AppointmentItem body text into to set the message. The EWSOofUtil.dll will set the Out of Office using EWS.

| improve this answer | |
  • How? Please provide the working code with the answer. – Jonas Stein Nov 25 '19 at 7:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.