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 :



  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Xml.Linq;
  6. using Outlook = Microsoft.Office.Interop.Outlook;
  7. using Office = Microsoft.Office.Core;
  8. using Microsoft.Office.Interop.Outlook;
  9.  
  10. namespace OutlookAddInExcludeFromReplyAll
  11. {
  12.     public partial class AddInExcludeFromReplyAll
  13.     {
  14.         private void ThisAddIn_Startup(object sender, System.EventArgs e)
  15.         {
  16.           Globals.AddInExcludeFromReplyAll.Application.ItemLoad +=
  17.              new Microsoft.Office.Interop.Outlook.ApplicationEvents_11_ItemLoadEventHandler(Application_ItemLoad);
  18.         }
  19.  
  20.         private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
  21.         {
  22.         }
  23.  
  24.         private void Application_ItemLoad(object Item)
  25.         {
  26.           if (Item is Outlook.ItemEvents_10_Event)
  27.             (Item as Outlook.ItemEvents_10_Event).ReplyAll +=
  28.                 new Microsoft.Office.Interop.Outlook.ItemEvents_10_ReplyAllEventHandler(ThisAddIn_ReplyAll);
  29.         }
  30.  
  31.         private void ThisAddIn_ReplyAll(object response, ref bool cancel)
  32.         {
  33.           MailItem mi = (MailItem)response;
  34.  
  35.           int recipientToRemoveIndex = -1;
  36.           foreach (Recipient rcp in mi.Recipients)
  37.           {
  38.             if (rcp.Address.StartsWith("no-reply@"))
  39.               recipientToRemoveIndex = rcp.Index;
  40.           }
  41.  
  42.           if (recipientToRemoveIndex != -1)
  43.             mi.Recipients.Remove(recipientToRemoveIndex);
  44.         }
  45.  
  46.  
  47.         #region VSTO generated code
  48.  
  49.         /// <summary>
  50.         /// Required method for Designer support - do not modify
  51.         /// the contents of this method with the code editor.
  52.         /// </summary>
  53.         private void InternalStartup()
  54.         {
  55.             this.Startup += new System.EventHandler(ThisAddIn_Startup);
  56.             this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
  57.         }
  58.        
  59.         #endregion
  60.     }
  61. }
  62.