Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / Languages / VBScript

OOF Automation

4.60/5 (2 votes)
31 Aug 2022CPOL3 min read 1   418  
Automated Setting of the Out of Office Assistant
This article shows how the OOFAutomation script automatically switches the OOF Assistant completely for the end user. Administration is supported with the extensive logging into a specified file.

Introduction

OOF (Out Of Office) Automation is a VBScript-based automation of switching the OOF Assistant on automatically when the respective user has entered an "away" appointment and back to off when there is no "away" appointment anymore.

This works by utilizing CDO externally using the Task Scheduler, e.g., all 30 minutes. There is also an internal solution to be found at CDOLive. However, I had a MAPI problem when implementing it, as my Outlook OOF Message was suddenly out of sync with the message modified within the script.

Using the Script

Every end user wishing to participate in the automated OOF Assistant switching has to set at least one (configurable) placeholder in his OOF Message in place of a date to be displayed in his final Message (e.g., "I'm out of the office <Date>. For urgent matters, please contact my... - Kind regards, Roland").

<Date> would then be replaced by from <begin date/time> to <end date/time>. from and to can be configured in the script for two languages (currently German and English). The respective placeholders are <Datum> and <Date>.

Once that is done, all the end user has to do is enter his absences as "away" appointments or whole day events. The OOFAutomation script will switch the OOF Assistant for him completely automatically. Administration is supported with the extensive logging into a specified file (see Installation below).

Installation

Installation is done by copying the two scripts into a folder reachable by the OOFAutomation server. This could be any Desktop PC or server that has either Outlook or Exchange Server installed. I haven't checked whether installation of a separately available CDO library would also be sufficient, but judging from Microsoft's statements on the download page, it ought to be.

After copying the script to the target folder, create a scheduled task on the OOFAutomation server that starts the script, e.g., every 30 minutes. The account that the task is run under needs to have administrative rights in Exchange or at least access rights to all end users' MAPI stores. Before activating the task, however, you have to configure the two scripts.

OOFAutomation.vbs

VBScript
'TO CONFIGURE: Change "ServerName" to the name of your Exchange Server
Const sServerName = "OEBFASRV02"

'TO CONFIGURE: Change "MailboxName" to the name 
'of an administrative mailbox on the server specified above
Dim sProfileInfo    ' the MAPI logon profile
sProfileInfo = sServerName & vbLf & "Administrator"

'TO CONFIGURE: Change placeholders and 
'infixes to reflect your used languages 
'(2 at most, if more are needed then change the code yourself...)
Const placeHolderLang1 = "<Datum>"
Const placeHolderLang2 = "<Date>"
Const infixFrom1 = "von "
Const infixFrom2 = "from "
Const infixTo1 = " bis "
Const infixTo2 = " to "
Const infixOn1 = "am "
Const infixOn2 = "on "

'TO CONFIGURE: Send Mails to these people in case of error.
Const ErrMailDistributionList = "rkapl"

Log.vbs

Log.vbs is a separately usable, simple Logger class. It can be used in other scripts as follows:

VBScript
Set WshShell = WScript.CreateObject("WScript.Shell")
ExecuteGlobal CreateObject(_
    "Scripting.FileSystemObject").OpenTextFile("Log.vbs", 1).ReadAll

' PathToLogFolder.. (default = defaultLogPath in Log.vbs)
' NameOfLogFile.. (default = scriptname)
' maxLevelToBeLogged.. 0 = ERROR, _
' 1 = WARN, 2 = INFO, 3 = DEBUG (default)
' CommaSeparatedErrMailDistributionListString... 
' e.g. "admin1, admin2, admin3" (default = defaultMailRecipients in Log.vbs)
' ErrMailSender.. (default = defaultMailSender in Log.vbs)
' ErrMailSubject.. (default = defaultMailSubject in Log.vbs)
Set theLogger = new_Logger(Array(PathToLogFolder,NameOfLogFile,_
    maxLevelToBeLogged,CommaSeparatedErrMailDistributionListString, _
    ErrMailSender,ErrMailSubject))

theLogger.LogInfo "Info Message"
theLogger.LogWarn "Warning Message"
theLogger.LogError "Error Message"
theLogger.LogStream (WshShell.Exec object) 
'logs stderr output of Exec object as 
'LogError messages, all other are logged as LogInfo
theLogger.LogFatal "Fatal Message (stops the script)"

However, it also needs to be configured before use:

VBScript
'TO CONFIGURE: Send Mails to these default 
'people in case of error (if not set by using script).
Const defaultMailRecipients = "rkapl,any,other,person"
'TO CONFIGURE: The default sender of the error mails
Const defaultMailSender = "Administrator"
'TO CONFIGURE: The default subject of error mails
Const defaultMailSubject = "Process Error"
'TO CONFIGURE: The file, where internal errors are logged
Const internalLogFile = _
    "\\path\to\your\internal\log\files\Log.vbs.internalErrs.log"
'TO CONFIGURE: The folder, where log files are being put
Const defaultLogPath = "\\path\to\your\Logs"

Finally, activate the task and test by entering the configured placeholder(s) in your OOFMessage text. Enter an "away" appointment that starts before now -1 minute and ends after now +1 minute.

Points of Interest

Of course, lots of the concepts used were taken from CDOLive.

History

  • 7th March, 2007: Version 1.0: CodeProject article posted
  • 10th March, 2007: Version 1.1: Bugfix for updating the OOF Message from Outlook. This is now possible as long as "I'm currently in the office" is selected and there is at least one of the placeholders (e.g., <Datum>) contained in the message.

New Version

In order to automate OOF settings starting from Exchange 2010, you can use https://rkapl123.github.io/ExchangeSetOOF/ - this uses the new EWS protocol (CDO is not being supported by newer versions of Exchange server).

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)