Last active
September 15, 2017 15:04
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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