Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><strong>UPDATE: Updated the code below using sample code adapted from <a href="http://vbadud.blogspot.com/2008_04_01_archive.html" rel="nofollow noreferrer">this blog post</a> which will work better in a wider variety of Outlook installations (e.g. ones using both Exchange and PST or accessing multiple Exchange mailboxes).</strong></p> <p>Here's code which worked for me on Outlook 2007, to set the OOF status from an external (to Outlook) EXE: </p> <pre><code>Microsoft.Office.Interop.Outlook.Application app = new Microsoft.Office.Interop.Outlook.ApplicationClass(); Microsoft.Office.Interop.Outlook.NameSpace ns = app.Session; foreach (Microsoft.Office.Interop.Outlook.Store store in ns.Stores) { if (store.ExchangeStoreType == Microsoft.Office.Interop.Outlook.OlExchangeStoreType.olPrimaryExchangeMailbox) { store.PropertyAccessor.SetProperty("http://schemas.microsoft.com/mapi/proptag/0x661D000B", true); // false to turn off OOF break; } } </code></pre> <p>Make sure you're not running that code as Administrator and outlook as non-Administrator-- otherwise you may get a security-related error on Vista.</p> <p>Note that it will pop up security dialogs inside Outlook to ensure the user is OK with you accessing the Outlook object model. This is normal when outlook object model is accessed from an external EXE.</p> <p>If, however, you're accessing the object model from an add-in, the code above isn't fully correct: instead of creating a new Outlook.Application object via the constructor, you you need to get a reference to the trusted Outlook.Application object from inside your add-in, like this:</p> <pre><code>Microsoft.Office.Interop.Outlook.NameSpace ns = this.Application.Session; foreach (Microsoft.Office.Interop.Outlook.Store store in ns.Stores) { if (store.ExchangeStoreType == Microsoft.Office.Interop.Outlook.OlExchangeStoreType.olPrimaryExchangeMailbox) { store.PropertyAccessor.SetProperty("http://schemas.microsoft.com/mapi/proptag/0x661D000B", true); // false to turn off OOF break; } } </code></pre> <p>BTW, there's a good <a href="http://msdn2.microsoft.com/library/1thd35d7(en-US,VS.80).aspx" rel="nofollow noreferrer">MSDN article</a> on security for add-ins, which may be useful if you run into security dialogs or errors.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload