Outlook addin: change inline response text - outlook-addin

With outlook VSTO addin I would like to change an email text when the user replies to an email. I manage to change the text when the response is not inline (i.e. when clicking "Reply" you also click "Pop out"). This is done by modifying MailItem.GetInspector.WordEditor.Range.Text.
However, when using inline response (without clicking "Pop out") modifying the above member throws an exception. I noticed that the reason is that in inline response the MailItem.GetInspector.WordEditor is protected (read only). so I use MailItem.GetInspector.WordEditor.Unprotect method for allowing modifications. after this, changing the text doesn't throw an exception any more but also doesn't have any effect - the text stays the same.
Same behavior when trying to modify Range.Text using OutlookSpy.
Why changing Range.Text doesn't have any effect for inline response?

For inline response, you should not be using MailItem.GetInspector.WordEditor, but Explorer.ActiveInlineResponseWordEditor.

Related

Outlook Addin: Updating AppointmentItem.Body breaks the RTFBody

In my Outlook addin I update the RTFBody (using WordEditor) and the Body of the AppointmentItem. After calling Save() on myAppointmentItem the layout shows broken for an rich text Appointment in Outlook. How can I prevent this from happening.
Obviously the ApppointmehtItem contains data in both places (RTFBody AND Body). Changing only one seems wrong to me. Any advice?
The Body property is a plain text representation of the RTFBody property. If you set the RTFBody property there is no need to set the plain text, it is done automatically. That is how Outlook syncs body-related properties.
Don't forget to call the Save method to apply your changes to make properties synced.

VSTO Outlook Plugin updates Appointment.Body and thus Outlook shows text instead of html part of multipart message

I receive multipart invitations which include calendar and text and html part. When I open those invitation mails in outlook it shows the html part.
Now my code updates the text part with:
myAppointment.Body = myAppointment.Body.Replace(OutlookAddIn4.Resources.Resources.LinkToMeeting + " " + meetingLink, "");
myAppointment.Save();
This text is normally NOT included in the text part. Therefore this call DOES NOT change anything.
Although Outlook now shows the text part instead of the HTML part.
My questions:
1.) How can avoid this?
2.) Is there a chance to determine in my Plugin whether Outlook shows the html part (RTFBody that is, right) or the text part?
Thanks
Hannes
Firstly, before unconditionally resetting the body, check if there is something to replace and only then do anything.
Secondly, you can take a look at the RtfBody property and set it instead. If HTML is used, RTF will have the "\fromhtml" header. Latest versions of Outlook support HTML, but HTMLBody property has not been added to the AppointmentItem object. In theory, you can set the PR_HTML property, but PropertyAccessor.SetProperty won't let you set it. If using Redemption is an option (I am its author), you can either set the RDOAppointment.HTMLBody property or set PR_HTML.

How to disable hyperlinks in selected MailItem instances?

I'm looking for a way to disable all hyperlinks in certain emails, but so far the only solution I've found was to set MailItem's body property with an version of the original email body that includes no links, which causes some problems. Does anyone know if there is an effective way to disable the links in an email body?
The Outlook object model doesn't provide anything for handling hyperlinks clicks. As a possible workaround you may consider implementing the following functionality:
When the item is selected or opened in Outlook you may replace the original URL with your own where you can pass the original URL as an encoded parameter if needed. So, if it is allowed to open the URL you can redirect the request further.
Another possible solution is to register a custom URL handler. So, basically, your registered application will be launched instead of a web browser. See Installing and Registering Protocol Handlers for more information.

Handling save event in Outlook

Good morning, I need my VBA code to run right before the TaskItem is saved, is there any way I can handle the event of saving ? I cannot find anything I could use in documentation. I am using MS-Office 2010.
Edit: I have tried
Private Sub TaskItem_Quit()
The macro disappears from macro list, but the code still does not run.
Try the Write event.
https://msdn.microsoft.com/en-us/library/office/ff868664.aspx
"Occurs when an instance of the parent object is saved, either explicitly (for example, using the Save or SaveAs methods) or implicitly (for example, in response to a prompt when closing the item's inspector)."

WatiN handler for vbscript Input Box

Do anyone have a solution for handling a vbscript inputbox with watin, and to be clear this is not the same a javascripts prompt or vbscript msgbox or etc....
I have and used handlers for those but cannot find a way to handle the input box and i do not have the pull to get the developers to change the code to use prompt and javascript like they have in some many other places in our old vb6 systems.
You should create a custom dialog handler that can handle the window. The trick to doing that is to get spy++ and match the right window style. Another method might be to call the document.eval method and close it using javascript.