Client-side rules won't run if the mailbox is not open in Outlook and you can't run rules on a shared mailbox in your profile. However, if the shared mailbox is in your profile you can use an ItemAdd macro to watch the folder for new items and process them as they arrive.
This sample watches a shared mailbox for new items, adds a category to the item then forwards it to another address.
To get the correct mailbox name to use, right-click on the shared Inbox and choose Properties. The mailbox name is in the Location field.
Use the name only, not the \\.
Private WithEvents olInboxItems As Items Private Sub Application_Startup() Dim objNS As NameSpace Set objNS = Application.Session ' Get function fromhttp://slipstick.me/qf Set olInboxItems = GetFolderPath("Mailbox name in folder list\Inbox").Items Set objNS = Nothing End Sub Private Sub olInboxItems_ItemAdd(ByVal Item As Object) On Error Resume Next Item.Categories = "My Category" Item.Save Set myForward = Item.Forward 'this puts the name in the To field myForward.Recipients.Add "firstname.lastname@example.org" myForward.Display ' use .Send to send it automatically End Sub
Don't forget to check your macro security settings; it needs to be set to Low for testing.
To test the macro without restarting Outlook, click in the Application_Startup macro and press Run.
How to use macros
First: You will need macro security set to low during testing.
To check your macro security in Outlook 2010 or 2013, go to File, Options, Trust Center and open Trust Center Settings, and change the Macro Settings. In Outlook 2007 and older, it’s at Tools, Macro Security.
After you test the macro and see that it works, you can either leave macro security set to low or sign the macro.
Open the VBA Editor by pressing Alt+F11 on your keyboard.
To put the code in a module:
- Right click on Project1 and choose Insert > Module
- Copy and paste the macro into the new module.
More information as well as screenshots are at How to use the VBA Editor