How to disable hyperlinks in selected MailItem instances? - outlook-addin

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.

Related

Add a hidden tag to outgoing mail

I create a mail by VBA when sending invoices and automated newsletters by Outlook (2019).
For reimporting the mails from the Sent folder into the database it would be convenient to read a hidden tag including the customer number which I would like to embed into the mail.
You can add a custom property either using MailItem.UserProperties.Add or by setting your custom property directly using MailItem.PropertyAccessor.SetProperty.
Keep in mind adding a user property can force Outlook to send in the RTF format (the infamous winmail.dat attachment), so the latter solution is preferable. You just need to make sure you get the DASL property name (to be used with MailItem.PropertyAccessor.SetProperty) right. You can use the former approach (MailItem.UserProperties.Add), take a look at the message in the Sent Items folder with OutlookSpy (I am its author - click IMessage button), then use the DASL property name replacing MailItem.UserProperties.Add with MailItem.PropertyAccessor.SetProperty

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 prevent image download in outlook form region?

We did an outlook addin with form regions to add tracking pixel img into email message upon sending.
What we want to make sure is to not load that same image when user goes to sent items and opens that message after sending.
Is there a way to do it through form regions or maybe some other better way?
Loading images in the HTML of the message body is controlled by the application and the behavior cannot be modified with code. The option to automatically download embedded images is controlled in Trust Center settings, so you could toggle this on/off by editing the registry (it should be stored there, perhaps not) but changing the setting in code probably won't take effect until Outlook is restarted. If you need to control this on a per-message basis then you are probably out of luck.

How to check for the active Application?

I made a VBA-Macro, activated via a Ribbon-Button for exporting selected Mails into a certain folder.
I'd like to make this Macro available in Word and Excel (for exporting doc/xls) into the same folder-structure.
Is it possible to check for the active application and then decide if a Mail(s)-Export or a simple Doc/Xls-Export should be done?
If you are working with multiple Applications probably the easiest way to identify one would be to use Application.Name property.
If you happen to have passed an object of some type that has the .Application property you can also call that. Refer to this post for details.
Also, with most MS-Office objects you can go up the hierarchy using the .Parent property to get all the way up to the Application, ie. .someObj.Parent.Parent.Parent.Application.Name

Using VSTO to perform an action via selected e-mail text in Outlook

This should be pretty a pretty common scenario, but I have not found a solution yet.
I would like to highlight some text within the body of an e-mail and then click on something (context menu, toolbar button, etc) to perform a URL navigation using the selected text. For example, highlight the Fex Ex tracking number and then navigate to their web site using it as a query parameter (like "ww.fedextracking.com?packageid=12345").
How can you capture the selected text within an e-mail and then perform an action? I would greatly appreciate any suggestions or examples.
Thank you!
For Outlook 2007-2010 (or previous versions using WordMail), you can retrieve a Word object from the Inspector.WordEditor property. Then you can work with Word.Selection to access the selected text.
However, for Plain Text or Rich Text scenarios with Outlook 2000-2003, you have to use the SafeInspector object with Redemption (http://www.dimastr.com/redemption/) to access the selected text. I can't remember, but for HTML format messages with Outlook 2003-2003 you may be able to access the selected text with the IHTMLDocument object retrieved from SafeInspector.
I appreciate it's 588 days since you asked your question Loki70, but if somebody else Googles up this page (like I did, looking for how to create a selected text right-click context menu entry) then this may be an answer for you.
I have been using AutoHotKey, which works not just in Outlook, but everywhere in Windows, and have been writing utilities to Google the selected text, open an SSH session in PuTTY to the selected hostname, and similar.
If you don't mind running an extra application on your PC to capture the hotkey combination that you send, then this would do exactly what you're asking.
Here is my post on the AutoHotKey forum with a link to my code:
http://www.autohotkey.com/community/viewtopic.php?t=86402
It would be trivial to adapt this to do the FedEx query you've mentioned.
I hope this helps.