Home > Net >  Hyperlink is showing as a STRING. Outlook Task for creating email holders
Hyperlink is showing as a STRING. Outlook Task for creating email holders

Time:01-31

I've tried all my luck, but I still can't figure out why my task.Body is not printing the Hyperlink that I want it to be.

I've tried changing it to HTMLBody, changing the bodyformat to 2 for it to be an HTML, Tried formatting it differently but I still get the same results.

I tried using HTMLBody but I get "property htmlbody cannot be set".

shortenedLink = f'<a href="https:/thelink{variable}">Hyperlink</a>' 

inviteItem.Body = shortenedLink
inviteItem.Save()
inviteItem.Display(true)

CodePudding user response:

The TaskItem class doesn't provide the HTMLBody property. Instead, you need to use the RTFBody one if you want to use any formatting in the message body. The property returns or sets a Byte array that represents the body of the Microsoft Outlook item in Rich Text Format.

But there is a trick - to use RTF in the body of a task, simply use the Body property. Setting this to a byte array containing RTF will automatically use that RTF in the body. Concretely, to get the body you want, you could use the following code:

task.Body = rb'{\rtf1{Here is the }{\field{\*\fldinst { HYPERLINK "https://www.python.org" }}{\fldrslt {link}}}{ I need}}'

CodePudding user response:

TaskItem object does not expose the HTMLBody property the way MailItem object does, even though Outlook is perfectly capable of displaying HTML in the UI.

You have a couple of options:

  1. Set the TaksItem.RTFBody instead. It is a binary (array) property, so the best way to figure out the value to be set is to take a look at an existing task with the RTF body set and use it as a template. At run-time, you can replace a placeholder and insert your own url in the array to be assigned to the RTFBody property. Note that OOM has a bug that prevents the RTFBody property from being set using late binding (like you'd be doing in Python or VBA), only early binding via the TaskItem interface works. You can take a look at the RTF body of an existing task with OutlookSpy (I am its author) - select or open a task in Outlook, click IMessage button, select the PR_RTF_COIMPRESSED property.

  2. If using Redemption is an option (I am also its author), it exposes RDOTaskItem.HTMLBody property.

  • Related