writing a script for Outlook rules RRS feed

  • Question

  • Hi there

    It's been a number of years since I used VBA— so— very rusty— and I've never used OutlookVBA at all. What I want to do should be very simple, I hope, but I don't know how to start.

    I want to write a rule to use for various mailers, mostly retailers, who are constantly sending mail. 90% is junk, but I don't want to automatically delete because occasionally I do buy something, and need to see the messages that follow when I do— receipts and so forth. Nor can I make a delete-exception, because the wording and format of the message will vary radically from one retailer to another.

    I'd like the message to trigger a dialog something like this: "Mail from ______ "  (The blank should be filled in with the sender's name, "Lehmans," for example)
    —followed by checkboxes: "delete?", "open?", or "save?"
    If it needs to be an either/or to keep it simple, I can live without the "open?" option.

    is this is simple as a I think it should be? Can anyone help, or point me in a direction where this has already been addressed?



    Wednesday, December 14, 2016 6:11 PM

All replies

  • Hello Nick,

    You can handle the NewMailEx event of the Application class which is fired when a new item is received in the Inbox.

    The NewMailEx event fires when a new message arrives in the Inbox and before client rule processing occurs. You can use the Entry ID returned in the EntryIDCollection array to call the NameSpace.GetItemFromID method and process the item. Use this method with caution to minimize the impact on Outlook performance. However, depending on the setup on the client computer, after a new message arrives in the Inbox, processes like spam filtering and client rules that move the new message from the Inbox to another folder can occur asynchronously. You should not assume that after these events fire, you will always get a one-item increase in the number of items in the Inbox.

    So, you can check the received item as soon as it comes to your Inbox and decide whether to show a dialog box or not.

    Finally, you may find the Getting Started with VBA in Outlook 2010 article helpful.

    profile for Eugene Astafiev at Stack Overflow, Q&A for professional and enthusiast programmers

    Wednesday, December 14, 2016 7:50 PM
  • Thank you, Eugene.  I don't think my knowledge base is sufficient to understand what you're saying, here. But I will take a look at the "Getting Started" article. Thanks again.


    Thursday, December 15, 2016 12:11 AM
  • Hi Nick_Vittum,

    here I think that suggestion given by Eugene  Astafiev can solve the issue.

    but in your last post you had mentioned that you have basic knowledge with Outlook VBA.

    so you want to go through the "Getting Started" article.

    so if you think that Eugene  Astafiev's suggestion can solve the issue then please mark it as an answer.



    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact

    Thursday, December 29, 2016 6:14 AM