I want to change the body at reply (also at replyAll and forward), so that the composer already get the modified message. So the SendEvent is not a possible solution. But in the reply event the changes at HTMLBody affects the original message immediately and forever. Changes are also instant visible in another Outlook instance. The composer (inline and window) don't show the change on the first editing.
I checked the subject of the "response object" and it already has the prefix "RE:" and is really the response itself. I don't understand, how to change only the response part.
I could also use the inspector of the response, but I don't know how to make the changes with the HTML editor. Using the word editor sounds like an overkill, so I didn't try.
My very simplified code:
using System;
using Outlook = Microsoft.Office.Interop.Outlook;
using System.Windows.Forms;
namespace OutlookAddInTEST
{
public partial class ThisAddIn
{
private Outlook.Application _application = null;
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
_application = Globals.ThisAddIn.Application;
_application.ItemLoad += new Outlook.ApplicationEvents_11_ItemLoadEventHandler(_application_ItemLoad);
}
private void ThisAddIn_Reply(object response, ref bool cancel)
{
Outlook.MailItem mitem = (Outlook.MailItem)response;
mitem.HTMLBody = mitem.HTMLBody.Replace("</body>", "# TEST # </body>");
}
Outlook.ItemEvents_10_Event _item;
private void _application_ItemLoad(object Item)
{
_item = (Outlook.ItemEvents_10_Event)Item;
_item.Reply += new Outlook.ItemEvents_10_ReplyEventHandler(ThisAddIn_Reply);
}
}
}
Instead of handling the
ItemLoadevent of theApplicationclass you can handle the SelectionChange event of theExplorerclass which is fired when the user selects a different or additional Microsoft Outlook item programmatically or by interacting with the user interface. So, you may subscribe to the events of currently selected item in theExplorerwindow. Don't forget to un-subsribe to the events and release the underlying COM objects when the item is not selected any longer.Also you may handle NewInspector event which is fired whenever a new inspector window is opened, either as a result of user action or through program code. A better solution is to implement an item wrapper, see Implement a wrapper for inspectors and track item-level events in each inspector for more information.
Use the ActiveInlineResponse property of the
Explorerclass which returns an item object representing the active inline response item in the explorer reading pane.The Explorer.InlineResponse event is fired when the user performs an action that causes an inline response to appear in the Reading Pane. This event returns an item object representing the inline response item.