Outlook and no-reply


Often I get mails from our server with various information, and me and my coworkers are all included, and in number of times I reply to that mail with some comments. Outlook 2010 includes that no-reply mail in recipients and every time I have to go to recipients list and manually remove that no-reply mails. It's annoying and I am pretty lazy. So I wrote little outlook 2010 addin to exclude such mails.

Visual Studio 2010 Solution - soruce code
Office 2010 instalation

Here is the source code :

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using Outlook = Microsoft.Office.Interop.Outlook;
using Office = Microsoft.Office.Core;
using Microsoft.Office.Interop.Outlook;
 
namespace OutlookAddInExcludeFromReplyAll
{
    public partial class AddInExcludeFromReplyAll
    {
        private void ThisAddIn_Startup(object sender, System.EventArgs e)
        {
          Globals.AddInExcludeFromReplyAll.Application.ItemLoad +=
             new Microsoft.Office.Interop.Outlook.ApplicationEvents_11_ItemLoadEventHandler(Application_ItemLoad);
        }
 
        private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
        {
        }
 
        private void Application_ItemLoad(object Item)
        {
          if (Item is Outlook.ItemEvents_10_Event)
            (Item as Outlook.ItemEvents_10_Event).ReplyAll +=
                new Microsoft.Office.Interop.Outlook.ItemEvents_10_ReplyAllEventHandler(ThisAddIn_ReplyAll);
        }
 
        private void ThisAddIn_ReplyAll(object response, ref bool cancel)
        {
          MailItem mi = (MailItem)response;
 
          int recipientToRemoveIndex = -1;
          foreach (Recipient rcp in mi.Recipients)
          {
            if (rcp.Address.StartsWith("no-reply@"))
              recipientToRemoveIndex = rcp.Index;
          }
 
          if (recipientToRemoveIndex != -1)
            mi.Recipients.Remove(recipientToRemoveIndex);
        }
 
 
        #region VSTO generated code
 
        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InternalStartup()
        {
            this.Startup += new System.EventHandler(ThisAddIn_Startup);
            this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
        }
       
        #endregion
    }
}