When working with Excelfiles it is very common to know how many rows there is to process in the file so that You can inform the user in a progressbar or something. I've seen a numerous examples of simple looping through each row until the ActiveCell is a nullvalue (empty string). This is not very ...

To create an email that contains a HTML body is a quite simple process, but there is a lot to
think about because of the variety of emailclients and their specific behaviour in how they implement
the HTMLCSS specifications. I will here try to guide You through the complete steps needed to ...

There is a lot to say when it comes to AJAX! If You have read the article "Integrating Ajax into traditional IBM Lotus Domino Web applications" (http:www-10.lotus.comlddddwiki.nsfdxIntegratingAjaxintotraditionalIBMLotusDominoWebapplications)
You will know how to use the Ajax response ...

I'm continuing the discussion on how to create a word document. Now it's time to understand how to format text in Word; This time I'll show how to write Bullet Lists into a word document. First, read up on how to create a word document here: ...

How to create and send an email message containing an HTML body using an agent

To create an email that contains a HTML body is a quite simple process, but there is a lot to
think about because of the variety of email-clients and their specific behaviour in how they implement
the HTML/CSS specifications. I will here try to guide You through the complete steps needed to
accomplish a mail that renders correctly in the recipients mailclient.

Step-by-step

We will fist declare the necessary variables...

Dim session As New NotesSession

Dim db As NotesDatabase

Dim doc As NotesDocument

Dim mimeRoot As NotesMIMEEntity

Dim mime As NotesMIMEEntity

Dim header As NotesMIMEHeader

Dim stream As NotesStream

Dim sHtml As String

As You will notice - we will be working with MIME enteties to create the mail, both the body and the mail header.

When working with the NotesMIMEEntety object, we must turn of the MIME conversion that is turned on by default.
This is extremely important, because if You forget to do this, You can experience serious troubles!

session.ConvertMime = False

Now we're ready to start creating the mail document:

Set db = session.CurrentDatabase

Set doc = db.CreateDocument

doc.Form = "Memo"

doc.Principal = "System"

You can change the Principal field to any text You want to display as the sender. Next step is to create the headers:

Set mimeRoot = doc.Createmimeentity

Set mime = mimeRoot.Createchildentity

Set header = mimeRoot.Getnthheader("Content-Type")

Call header.SetHeaderval("multipart/related")

doc.Subject = "Test of HTML Mail"

Set header = mime.CreateHeader("Subject")

Call header.Setheaderval("Test of HTML Mail")

Why defining the subject twice (both in the Subject field and as a MIME header value)?
Well, that is because the recipient(s) client(s) can choose to NOT display HTML and only show the
text part of the mail - and therefore You need to define the field as well. It is the field that will become
the text representation of the subject.

Did You notice something odd with the HTML code? How about the imgage source and the background source?
It said 'cid:leaf.gif' and 'cid:logotype.jpg'. Well, it is a marker for the MIME object that it should insert a picture from
another MIME object inside the same message. Therefore we will need to attach the images as well into MIME
objects and here comes a really bad thing when attaching files into a Notesdocument: You must have access to
the file system and therefore You need to think about a couple of things:

1) Is the agent going to be run on the server or locally?
If You run it only locally - then the picture files must reside on the local computer that runs the agent.
If You run it scheduled on a server - then the picture must reside on the servers filesystem and here comes another
thing: You must therefore also set the agent security properties to allow restricted operations.

So, time to attach the HTML body:

Set stream = session.CreateStream

Call stream.WriteText(sHtml)

Call mime.SetContentFromText(stream,"text/html",ENC_NONE)

Call stream.Close

We now attach the images:

' Create Inline image reference:

Set mime = mimeRoot.Createchildentity

Call stream.Open("C:\Temp\leaf.gif")

Call mime.SetContentFromBytes(stream,"image/gif",ENC_NONE)

Call stream.Close

Call mime.EncodeContent(ENC_BASE64)

Set header = mime.CreateHeader("Content-ID")

Call header.SetHeaderVal("<leaf.gif>")

' Next picture:

Set mime = mimeRoot.Createchildentity

Call stream.Open("C:\Temp\logotype.jpg")

Call mime.SetContentFromBytes(stream,"image/jpg",ENC_NONE)

Call stream.Close

Call mime.EncodeContent(ENC_BASE64)

Set header = mime.CreateHeader("Content-ID")

Call header.SetHeaderVal("<logotype.jpg>")

Now, if the mail is like a newsletter where You don't want do display the recipients names, then we do like this:

More information: Differences in mail clients implementation of HTML and CSS standards

Now, a couple of last warnings... As I mentioned earlier, there are differences in how the mail clients have
implemented the HTML and CSS standards. For instance, Gmail does not allow the style-tag to be defined
at ALL and will therefore be removed before rendering the message. That is why we need to use the style
property of each HTML tag. To learn more about the differences,
take a look at Guide to CSS support in email clients.

One thing about the list though: It is incorrect when it states that Lotus Notes 8.5 doesn't support the background
property in CSS. I have successfully used this property many times with Lotus Notes clients. The same goes
with "background-position".