I hear from a lot of user's who don't like how Outlook handles sent items with an IMAP accounts. In older versions of Outlook, IMAP sent items use the local Sent Items folder. While Outlook 2007 and 2010 can be configured to use the IMAP sent folder, when you use a Send by email command in other applications, the sent item goes into the local data file, ignoring the account configuration. Outlook 2013 uses XLIST to determine the sent items folder, but if the IMAP server doesn't support XLIST, the sent item is saved locally.
This macro solves the problem by monitoring the sent items folder and moving sent messages to the desired folder.
To use this macro, you need to use the GetFolderPath macro from GetFolderPath.
You'll also need to set macro security to low to test the macro.
Press Alt+F11 to open the VBA editor. Expand Project1 and Microsoft Outlook Objects then double click on ThisOutlookSession. Paste the code into ThisOutlookSession. GetFolderPath can be pasted below this macro or in a new module.
To use this with multiple accounts, copy the IF... End IF block and change the account name and folder path for each account.
The account name and the data file name are usually the same - in Outlook 2010, both are the email address by default.
You need to use the account name as seen in File, Account Settings (or in the From field if you have multiple accounts) and the data file name (and path to the Sent folder) as seen in the folder list.
Note: this macro will work with any account type.
This macro starts when Outlook stars. To test it without restarting Outlook, click in the Application_Startup macro and click the Run button (or press F5).
Private WithEvents Items As Outlook.Items Private Sub Application_Startup() Set Items = Session.GetDefaultFolder(olFolderSentMail).Items End Sub Private Sub Items_ItemAdd(ByVal Item As Object) 'repeat for each account If Item.SendUsingAccount = "firstname.lastname@example.org" Then ' Get the GetFolderPath function from http://slipstick.me/getfolderpath Set MovePst = GetFolderPath("data file name\Inbox\Sent") Item.UnRead = False Item.Move MovePst End If End Sub
To move sent messages to multiple folders, you can repeat the If / End If block in the code sample above or set the MovePst variable in each If statement, like so:
If Item.SendUsingAccount = "email@example.com" Then Set MovePst = GetFolderPath("data file name1\Inbox\Sent") End If If Item.SendUsingAccount = "firstname.lastname@example.org" Then Set MovePst = GetFolderPath("data file name2\Inbox\Sent") End If Item.UnRead = False Item.Move MovePst
You could also use Case statements to set the correct Move path.