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

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.

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

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.

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.

Get selected text from subject line

I have searched and found this answer but it won't seem to work for me. I need to get the selected (highlighted) text from the subject of the email. When I try the linked solution from either the preview pane or from an open email, I only get the first character of the body. I attempted to look at all properties of mail.GetInspector.WordEditor but nothing seems to contain the selected text. As stated, mail.GetInspector.WordEditor.Application.Selection only has the first character of the body. In my code, I have mail as type MailItem and is set to ActiveExplorer.Selection.Item(1).
My code works fine when the selected text is in the body of the email.
You need to find the Windows control containing the subject and send WM_GETTEXT message to it.
I don't think you can do that in VBA.

Change hyperlink based on date in Outlook 2013

Every day our Helpdesk has to send out a report. That report needs to link to a website that displays that days statistics.
Example URL:
http://hostname/dashboardname/date
Which would look like this:
http://hostname/HelpdeskTickets/2015-03-18
Heres what I've tried:
First I looked into field code values and doing something like this
{HYPERLINK "http://hostname/HelpdeskTickets/{DATE \# "yyyy-MM-dd"}"}
And this works, until you close the outlook message. If you don't have F9 to update the field code, and save and close the .msg file it will disappear leaving just the blank link without a date. If you hit F9 before closing it, it puts that days date into the field, however when you close and save it the field code disappears and leaves the date in place of the date field code. Also I noticed this problem doesn't happen in word. You can save and close a word file and it keeps the field codes.
Another thing I've tried is to use VBA to edit the links in the message body. So far nothing has actually worked.
The only thing that partially worked was taking the body of the document and using a string replace function on it. However this destroys all formatting and hyperlinks along with it.
I'm open to any ideas on how this can be achieved.
My main problem is that the people at the helpdesk can't seem to use anything that isn't fool proof. So having them press F9 before sending this email was actually scaring people that they wouldn't be able to do that.
You can use VBA to edit the message body programmatically. It is not clear what code you used earlier, but the main ways are described below:
HTMLBody - a string representing the HTML body of the specified item. The HTMLBody property should be an HTML syntax string.
The Word editor. The WordEditor property of the Inspector class returns an instance of the Document class from the Word object model. So, the message body is represented by the Word Document.
You can read more about all possible ways in the Chapter 17: Working with Item Bodies.