Is it possible to set up rule in Outlook 2010 based on message class?

6,030

You can't do that with Outlook rules. But you can with Outlook macros. First, enable macros in Outlook Options' Trust Center. Then in Outlook press ALT+F11 to open VBA and paste the following macro to ThisOutlookSession. After that, save changes and restart Outlook. The macro will move all NDRs to "NDR" subfolder of your Inbox. It will also create this subfolder if necessary. Fell free to replace ("NDR") with your own folder name if needed.

Private WithEvents Items As Outlook.Items

Private Sub Application_Startup()
    Set Items = Session.GetDefaultFolder(olFolderInbox).Items
End Sub

Private Sub Items_ItemAdd(ByVal Item As Object)
    On Error Resume Next

    If UCase(Item.MessageClass) = "REPORT.IPM.NOTE.NDR" Then
        Set Folders = Session.GetDefaultFolder(olFolderInbox).Folders
        Set Folder = Folders.Item("NDR")
        If Folder Is Nothing Then
            Folder = Folders.Add("NDR")
        End If
        Item.Move Folder
    End If
End Sub
Share:
6,030

Related videos on Youtube

SinisterBeard
Author by

SinisterBeard

PHP, JS, MySQL, JQuery, React

Updated on September 18, 2022

Comments

  • SinisterBeard
    SinisterBeard over 1 year

    I recieve all the undeliverable reports for mailings sent from my company. Moving and cataloguing them can take a while, and it would be handy if I could create a rule that did that for me.

    The most robust way of doing this would seem to be to run a rule based on the Undeliverable message class. However, I can't see message class as an option anywhere in the advanced rules wizard, and Googling it is no help.

    EDIT: I already have a rule that searches for "Undeliverable" in the subject header of emails received and moves them, but this only affects traditional emails (i.e. those with a message class of "Message") and ignores actual undeliverable reports.

    Am I missing something obvious, or can this not be done?

  • SinisterBeard
    SinisterBeard over 10 years
    Hi - this is what I've got set up currently, but this only catches emails with the message class "Message" (i.e. standard e-mails) and "Undeliverable" in the title, and ignores actual undeliverable reports, hence this question - I should have said this above, so will edit my original question as well.
  • SinisterBeard
    SinisterBeard over 10 years
    Works like a dream, if you dream about code. Thanks, @thims.