Link to home
Start Free TrialLog in
Avatar of SavindraSingh
SavindraSinghFlag for India

asked on

Automating OOO (out of office) Assistant in Outlook

This is with reference to an article written by user BlueDevilFan available at below link:

https://www.experts-exchange.com/Software/Office_Productivity/Groupware/Outlook/A_3487-Automating-Out-of-Office-in-Outlook.html?cid=239

I am looking for automating Microsoft Outlook 's OOO assistant so that it can automatically turn on/off the OOO assistant basis on the events/appointments saved on the outlook calendar.

For example:

If I have an all day event/appointment item stored on calendar with its BusyStatus set to olOutOfOffice. I was thinking about the event which will turn the OOO assistant on at the time given for this event/appointment in calendar and then automatically turn it off when the event/appointment time is ended.

While thinking on these lines I got an idea that this can be enabled when the Application_Reminder event gets triggered. So I had written below code in order to capture the event and then run the procedure to turn on OOO assistant.
Sub OutOfOffice(bolState As Boolean)
    Const PR_OOF_STATE = "http://schemas.microsoft.com/mapi/proptag/0x661D000B"
    Dim olkIS As Outlook.Store, olkPA As Outlook.PropertyAccessor
    For Each olkIS In Session.Stores
        If olkIS.ExchangeStoreType = olPrimaryExchangeMailbox Then
            Set olkPA = olkIS.PropertyAccessor
            olkPA.SetProperty PR_OOF_STATE, bolState
        End If
    Next
    Set olkIS = Nothing
    Set olkPA = Nothing
End Sub

'Above code is provided by BDF and below code is written by me'

Private Sub Application_Reminder(ByVal Item As Object)

If Item.BusyStatus = olOutOfOffice Then
    OutOfOffice True
End If

End Sub

Open in new window


By capturing the Application_Reminder events we can get reference to the current calendar item which has triggered the event and we can get below properties from it:

(1) Item.BusyStatus - Can be used to check if that is a out of office event
(2) Item.Body - Can be used to set the message that we need to put in OOO auto reply email message body
(3) Item.Location - Can be used to include this info in reply email message
(4) Item.Subject -  Can be used to specify the subject line of reply email
(5) Item.StartInStartTimeZone - Can be used to specify the time when the OOO should turn on
(6) Item.EndInEndTimeZone - Can be used to specify the time when the OOO should turn off

But there are few constraints in doing this:
1) How to pass the Message body, Subject, Location etc info to be included in OOO email message, to the function/code provided by BDF
2) How can we turn off OOO at the time captured by Item.EndInEndTimeZone

Any help in this regard is highly appreciated.
ASKER CERTIFIED SOLUTION
Avatar of David Lee
David Lee
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of SavindraSingh

ASKER

By using Visual studio 2010, we can create Outlook add-ins. I have create one by converting your code to C#.Net:

using Outlook = Microsoft.Office.Interop.Outlook;

namespace O3_Extender
{
    public partial class OOOExtender
    {
        Outlook.Application outlookApp = new Outlook.Application();

        private void ThisAddIn_Startup(object sender, System.EventArgs e)
        {
            if (CheckOOOStatus()==true)
            {
                OutOfOffice(false);
                System.Windows.Forms.MessageBox.Show("Out of office assistant was on since last login. It is turned off now!","Out of Office Assistant",System.Windows.Forms.MessageBoxButtons.OK,System.Windows.Forms.MessageBoxIcon.Information);
            }
        }

        private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
        {
        }
    void OutOfOffice(bool bolState) 
    {
        Outlook.NameSpace ns = outlookApp.Session;
        string PR_OOF_STATE = "http://schemas.microsoft.com/mapi/proptag/0x661D000B";
        
        Outlook.PropertyAccessor olkPA;
        foreach (Outlook.Store olkIS in ns.Stores)
	    {
            if(olkIS.ExchangeStoreType == Outlook.OlExchangeStoreType.olPrimaryExchangeMailbox) 
            {
                olkPA = olkIS.PropertyAccessor;
                olkPA.SetProperty(PR_OOF_STATE, bolState);
            }
	    }   
            olkPA = null;
    }

    bool CheckOOOStatus()  /* Code to return current status of OOO */
    {
        bool OOOStatus = true;
        Outlook.NameSpace ns = outlookApp.Session;
        string PR_OOF_STATE = "http://schemas.microsoft.com/mapi/proptag/0x661D000B";

        Outlook.PropertyAccessor olkPA;
        foreach (Outlook.Store olkIS in ns.Stores)
        {
            if (olkIS.ExchangeStoreType == Outlook.OlExchangeStoreType.olPrimaryExchangeMailbox)
            {
                olkPA = olkIS.PropertyAccessor;
                OOOStatus = olkPA.GetProperty(PR_OOF_STATE);
            }
        }
        olkPA = null;
        return OOOStatus;
    }

        #region VSTO generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InternalStartup()
        {
            this.Startup += new System.EventHandler(ThisAddIn_Startup);
            this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
        }
        
        #endregion
    }
    
}

Open in new window


The above code can simply check the status of OOO while logging in to Outlook and turn it off if it is on.

Can you help me to extend it to sync it with Calendar events.

Regards,
Savindra
There is another problem with this approach.

I believe that the add-in code will stop working when the Outlook is not running this will prevent the code from turning on OOO if the users logoff  before the OOO event occurs. Correct me if I am wrong.
That's correct.  There is no client-side solution for this.  If you want this functionality whether the user is logged in or not, then you'll have to develop a server-side solution.  That's quite a bit more complicated.
Thanks BDF I will continue with my research on server side solution. Your comments were very helpful.
Need to think about sonthing else.