Lookup email address before send executes and warn if on list RRS feed

  • Question

  • I'd like to know how to have Outlook reference a "Do Not Email" list/file prior to sending an email. I'd like to warn if an email in the TO, CC, or BCC is included in the list and if so, warn that the email is in the list. I have close to 700,000 emails to check. Suggestions?
    Wednesday, December 28, 2016 1:41 AM

All replies

  • Process the Application.ItemSend event (the message being sent will be passed as a parameter). Loop through the MailItem.Recipients collection and for each recipient check that Recipient.Address is on the list. If so, set the Cancel by-ref parameter to true to prevent the message from being sent.

    Dmitry Streblechenko (MVP)
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Wednesday, December 28, 2016 5:32 AM
  • Hello Grady,

    It is not clear what programming language you are going to use... Basically, as Dmitry already wrote, you need to handle the ItemSend event of the Application class which is fired whenever an Microsoft Outlook item is sent, either by the user through an Inspector (before the inspector is closed, but after the user clicks the Send button) or when the Send method for an Outlook item, such as MailItem, is used in a program. 

    using System.Runtime.InteropServices;
    // ...
    private void ThisAddIn_Startup(object sender, System.EventArgs e)
        Application.ItemSend += new 
    void Application_ItemSend(object Item, ref bool Cancel)
        Outlook.Recipient recipient = null;
        Outlook.Recipients recipients = null;    
        Outlook.MailItem mail = Item as Outlook.MailItem;
        if (mail != null)
            string addToSubject = " !IMPORTANT";
            string addToBody = "Sent from my Outlook 2010";
            if (!mail.Subject.Contains(addToSubject))
            mail.Subject += addToSubject;
            if (!mail.Body.EndsWith(addToBody))
            mail.Body += addToBody;
            recipients = mail.Recipients;
            recipient = recipients.Add("Eugene Astafiev");
            recipient.Type = (int)Outlook.OlMailRecipientType.olBCC;
            if (recipient != null) Marshal.ReleaseComObject(recipient);
            if (recipients != null) Marshal.ReleaseComObject(recipients);

    You may also find the following articles helpful:

    How To: Change an Outlook e-mail message before sending using C# or VB.NET

    HowTo: Handle the Outlook ItemSend event: C#, VB.NET examples

    The How To: Fill TO,CC and BCC fields in Outlook programmatically article explains how to deal with TO, CC and BCC fields programmatically. 


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

    Wednesday, December 28, 2016 7:40 PM
  • Thank you!
    Tuesday, January 3, 2017 6:36 PM
  • Thank you.

    Tuesday, January 3, 2017 6:37 PM