Change ActiveInlineResponseWordEditor from Outlook 2007 Add-in

I got an Outlook 2007 plugin that at the Application.ItemSend event makes a small change for each hyperlink in an email. This is accomplished by getting the Inspector.WordEditor property of the active inspector and viewing the Hyperlinks property.

Unfortunately, since the introduction of Office 2013, this method does not work with the built-in reply function, which means that quick replies are ignored.

I am making changes to this plugin to try and make this work, but I am encountering some strange behavior.

When running locally, with or without a debugger, I can use reflection to get the ActiveInlineResponseWordEditor Application.ActiveExplorer () property and make the same changes, and everything looks good.

When I package this solution and install it on a test machine, the code is expected to still execute (I can see this from some logging I do), the changes I make are not actually saved in the sent email - only for built-in answers, all other functions work correctly.

I am accessing the document using the following snippet:

Word.Document doc = null;

var explorer = Application.ActiveExplorer();
var wrapper = InspectorWrapper.GetWrapperFor(mailItem.GetInspector, logger);

try
{
    doc = (Word.Document)explorer.GetType().GetProperty("ActiveInlineResponseWordEditor").GetValue(explorer, null);
}
catch (TargetInvocationException) { /*Silently fail */ }

if (doc == null)
{
    if (wrapper is MailItemWrapper)
    {
        doc = wrapper.Inspector.WordEditor as Word.Document;
        logger.Log("Have inspector document.");
    }
}
else
{
    logger.Log("Have in-line document.");
}

      

And I am using this document to change all links that are done with this snippet:

foreach (Word.Hyperlink link in doc.Hyperlinks)
{
    var uriBuilder = new UriBuilder(link.Address);

    var query = HttpUtility.ParseQueryString(uriBuilder.Query);
    query.Set("id", 1);

    uriBuilder.Query = query.ToString();

    var newLink = uriBuilder.ToString();

    logger.Log(string.Format("{0} to {1}", link.Address, newLink));

    link.Address = newLink;
}

      

I tried to just access the MailItem.GetInspector property, but the same symptoms are coming out. I also tried to call mailItem.Save () after the changes finished, again there are symptoms.

My guess is that I am not getting a valid link to the Word editor and therefore the changes are not being saved, but does anyone have any ideas?

+3


source to share


2 answers


Try to read the HTML of the outgoing message, load it into an IHTMLDocument object, change the links, then reset the HTMLBody property.



+1


source


Please take a look at this link, it might help your question a little:

http://www.add-in-express.com/creating-addins-blog/2012/10/19/customize-outlook2013-inline-response/

Important section:

How to get inline reply item in Outlook 2013

Here they mention an insert from a link:

"Remember, if you are building an add-in that supports earlier versions of Outlook and also using version neutral transitions, you need to use late binding technology to access the ActiveInlineResponse property."



the code looks like this:

explorer = OutlookApp.ActiveExplorer();
        // response = explorer.ActiveInlineResponse;
        response = explorer.GetType().InvokeMember("ActiveInlineResponse",
                             System.Reflection.BindingFlags.GetProperty | 
                             System.Reflection.BindingFlags.Instance |
                             System.Reflection.BindingFlags.Public, 
                             null, explorer, null) as Outlook.MailItem;

      

My understanding is that to use the "ActiveInlineResponseWordEditor" property, you need to use a late binding since you have a backward compatible admin - 2007, 2010. Please try if this modification works for you and you can get the object doc, which works similarly to earlier versions of Outlook.

You should try the following code:

doc = explorer.GetType().InvokeMember("ActiveInlineResponseWordEditor",
                                 System.Reflection.BindingFlags.GetProperty | 
                                 System.Reflection.BindingFlags.Instance |
                                 System.Reflection.BindingFlags.Public, 
                                 null, explorer, null) as Word.Document;

      

+2


source







All Articles