Skip to content

Instantly share code, notes, and snippets.

@damianh
Last active September 15, 2017 15:04
Show Gist options
  • Save damianh/d03ef8e4a4c69b0b1ee1b7d87669e542 to your computer and use it in GitHub Desktop.
Save damianh/d03ef8e4a4c69b0b1ee1b7d87669e542 to your computer and use it in GitHub Desktop.
Dumb find-replace-save outlook addin for incoming email. Creating Your First VSTO Add-In for Outlook: https://msdn.microsoft.com/en-us/library/cc668191.aspx
public partial class SignatureRemoverAddIn
{
private void SignatureRemoverAddIn_Startup(object sender, EventArgs e)
{
var outlookNameSpace = this.Application.GetNamespace("MAPI");
var inbox = outlookNameSpace.GetDefaultFolder(OlDefaultFolders.olFolderInbox);
var items = inbox.Items;
items.ItemAdd += ItemsOnItemAdd;
}
private void ItemsOnItemAdd(object item)
{
if (item is MailItem mail)
{
if (mail.MessageClass == "IPM.Note" && !string.IsNullOrWhiteSpace(mail.HTMLBody))
{
mail.HTMLBody = RemoveSignatureCrap(mail.HTMLBody);
mail.Save();
}
}
}
public static string RemoveSignatureCrap(string body)
{
// find and remove stuff here
}
private void SignatureRemoverAddIn_Shutdown(object sender, EventArgs e)
{
// Note: Outlook no longer raises this event. If you have code that
// must run when Outlook shuts down, see https://go.microsoft.com/fwlink/?LinkId=506785
}
#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()
{
Startup += SignatureRemoverAddIn_Startup;
Shutdown += SignatureRemoverAddIn_Shutdown;
}
#endregion
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment