HTML link works even though HTML text is ignored

This developer is trying to send an HTML anchor link, and wants to know why the HTML text is ignored, shows as source code, and yet the link still works.

I am attempting to send a HTML anchor link "<HTML><Head><BODY><a href="http://+"+ ServerName + DbName + "formname?OpenForm&ParentUNID=" + DocUNID + ">" + Anchor text + "</a>=></HTML>=></HEAD></BODY>" from the web. The HTML text is ignored and shows as source code, but the link works. Any suggestions?

The link works because the recipient's mail program recognizes the URL syntax within the message text and makes it an active link when it displays it.

I'm not sure what programming language you're working in. I'm going to assume LotusScript.

When converting a message that contains just text to Internet format (MIME), Domino doesn't treat the text as HTML. Instead, it assumes that if the text contains a >, you want the recipient to see a <. So it "escapes" the >, changing it to <, so that the receiving e-mail program doesn't mistake it for HTML and try to interpret it as a tag.

There are a few ways to tell the Domino mail gateway that you really intended to use HTML in your message. One is to not use HTML, but instead use the corresponding rich text entities. This works great if you wanted to set the color, font or style of text. Unfortunately, there's no support with the rich text APIs in LotusScript or Java to create URL links. You can use NotesRichTextStyle.PassThruHTML property to designate certain parts of your message as HTML code. However, I'm not certain that the mail gateway pays attention to this setting.

From a developer's perspective, an easier way is to manually create the exact rich text you want to send and store it in a Notes document somewhere -- a configuration document for your application. You can use a profile document for this or a "normal" document. That lets you use Create / Hotspot / Link Hotspot to make the URL link. In the agent that sends the e-mail, use the NotesDocument object to retrieve this configuration document, GetFirstItem to retrieve the rich text field containing the URL link, and either CopyItem or AppendRTItem to move the rich text into the message that you're creating. The Domino Designer 6 Redbook contains an example of this technique in the chapter on rich text programming.

Another way is to bypass the rich text to MIME conversion by using MIME yourself in the first place. I just wrote an article about this, entitled Using HTML, MIME and LotusScript to jazz up messages and reports. If you're not a subscriber to The View (the publication it appeared in), you can still download the sample database and try it out (Create / MIME code generator). Here's some sample source code it generated for a simple message, including a URL link:

Set result = doc.CreateMIMEEntity("Body") 
Dim hdr As NotesMimeHeader 
' text entity, encoding type ENC_NONE 
Dim stream As NotesStream 
Dim session As New NotesSession 
Set stream = session.CreateStream 

Please take our annoying survey! Clickhereto begin. |) result.SetContentFromText stream, "text/html", ENC_NONE Call doc.CloseMIMEEntities(True, "Body") ' finalize pending changes into the document.

Do you have comments on this Ask the Expert question and response? Let us know.

Dig Deeper on LotusScript

  • Favorite iSeries cheat sheets

    Here you'll find a collection of valuable cheat sheets gathered from across the iSeries/ community. These cheat ...