Skip to main content link. Accesskey S
  • Help
  • HCL Logo
  • HCL Notes and Domino Application Development wiki
  • THIS WIKI IS READ-ONLY. Individual names altered for privacy purposes.
  • HCL Forums and Blogs
  • Home
  • Product Documentation
  • Community Articles
  • Learning Center
  • API Documentation
Search
Learning Center > Tutorials > How to create and send an email message containing an HTML body using an agent
  • Share Show Menu▼
  • Subscribe Show Menu▼

Recent articles by this author

Traversing XML result of AJAX request with JQuery

When working with JQuery and Ajax, there is simply no simple good instructions on how to traverse the complete tree of an XML result of an Ajax call. This is how You do it.

A shortcut for get the number of rows used in Excelfile/Worksheet

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 ...

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 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 ...

Using XML response from Ajax call in Lotus Domino Web applications

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 ...

HowTo: Create Bullet List in Word Document

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: ...
Learning Center articleHow to create and send an email message containing an HTML body using an agent
Added by ~Richard Zekboosilyettu | Edited by ~Richard Zekboosilyettu on October 1, 2012 | Version 6
  • Actions Show Menu▼
expanded Abstract
collapsed Abstract
No abstract provided.
Tags: htmlmail, lotusscript, html, mail, tutorials
ShowTable of Contents
HideTable of Contents
  • 1 Step-by-step
    • 1.1 Complete code listing
  • 2 More information: Differences in mail clients implementation of HTML and CSS standards

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.

Now, lets set the recipients address(es) and the "From" address:

 

	Set header = mime.CreateHeader("To")

	Call header.SetHeaderval("kenneth.axi@lycos.com")

	Set header = mime.CreateHeader("From")

	Call header.setheaderval("no-reply@lycos.com")

	

It is finally time to define the HTML body. Let's assign all the HTML code into a string variable:


	sHtml = |

	<style>

	body {font-family:Verdana,Arial,sans-serif;

	color:black;

	font-weight:normal;

	font-size:10px;

	}

	h3 { font-family:Verdana,Arial,sans-serif;font-size:17px; font-weight:normal; color:black;}

	table,tr,td {font-family:Verdana,Arial,sans-serif;font-size:11px;font-weight:normal; color:black;}

	th {font-family:Verdana,Arial,sans-serif;font-size:11px;font-weight:bold;color:black;}

	</style>

	<table border="0" cellspacing="0" cellpadding="0">

	<tr>

	<td style="font-family:Verdana,Arial,sans-serif;font-size:11px;font-weight:normal;color:black;

	background-repeat:no-repeat;background-position:right bottom;" background="cid:leaf.gif">

	<div style="font-size:11px; padding-left:25px;padding-right:10px;padding-top:8px;width:630px;

	border:2px solid #0087A9;">

	<img src="cid:logotype.jpg" border="0" alt="D-Link Logo" align="left" height="32" width="147" />

	<br /><br /><br /><br />

	<p style="font-family:Verdana,Arial,sans-serif;font-size:11px;padding-left:15px; padding-right:10px;color:black;">

	<h1 style="font-family:Verdana,Arial,sans-serif;font-size:17px; font-weight:normal; color:black;">

	** This is an automated message, please do not reply **</h1>

	<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur dapibus vehicula sapien

	in vulputate. Nullam rhoncus dolor at erat faucibus scelerisque. Donec a tristique purus. Class aptent

	taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Donec eget urna sit amet

	ligula aliquet lacinia. Praesent fringilla elementum quam et vulputate. Nam bibendum, sapien sed

	adipiscing sodales, augue neque euismod tortor, eget ornare tortor justo id tellus. Fusce id lorem

	at nulla laoreet eleifend. Fusce odio diam, aliquam in semper sit amet, condimentum eget odio.

	Praesent dapibus urna condimentum mi rhoncus venenatis. Morbi ullamcorper libero in ligula tempor

	hendrerit. Vivamus pretium pharetra malesuada. Vestibulum cursus turpis eget risus ultricies faucibus

	eu eget urna. Donec aliquet convallis pulvinar.

	</p>

	<br />

	<br />

	</div>

	</td></tr></table>|

	

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:

 

	Dim rec(2) As String

	rec(0) = "some.emailaddress@acme.com"

	rec(1) = "another.emailaddress@acme2.com"

	rec(2) = "abc@def.com"

	Dim itm As NotesItem

	Set itm = New NotesItem(doc,"Recipients","no-reply@lycos.com",NAMES)

	doc.SendTo = "no-reply@lycos.com"

	doc.BlindCopyTo = rec

	

Finally - time to send the mail! Oh - and don't forget to turn on the MIME conversion at the very end of the agent!


	Call doc.Send(False)

	session.ConvertMime = True

	

Complete code listing

Here is the complete code as described above:


	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

	session.ConvertMime = False

	Set db = session.CurrentDatabase

	Set doc = db.CreateDocument

	doc.Form = "Memo"

	doc.Principal = "System"

	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")

	Set header = mime.CreateHeader("To")

	Call header.SetHeaderval("kenneth.axi@lycos.com")

	Set header = mime.CreateHeader("From")

	Call header.setheaderval("no-reply@lycos.com")

	sHtml = |

	<style>

	body {font-family:Verdana,Arial,sans-serif;

	color:black;

	font-weight:normal;

	font-size:10px;

	}

	h3 { font-family:Verdana,Arial,sans-serif;font-size:17px; font-weight:normal; color:black;}

	table,tr,td {font-family:Verdana,Arial,sans-serif;font-size:11px;font-weight:normal; color:black;}

	th {font-family:Verdana,Arial,sans-serif;font-size:11px;font-weight:bold;color:black;}

	</style>

	<table border="0" cellspacing="0" cellpadding="0">

	<tr><td style="font-family:Verdana,Arial,sans-serif;font-size:11px;font-weight:normal;color:black;

	background-repeat:no-repeat;background-position:right bottom;" background="cid:leaf.gif">

	<div style="font-size:11px; padding-left:25px;padding-right:10px;padding-top:8px;width:630px;

	border:2px solid #0087A9;">

	<img src="cid:logotype.jpg" border="0" alt="D-Link Logo" align="left" height="32" width="147" />

	<br /><br /><br /><br />

	<p style="font-family:Verdana,Arial,sans-serif;font-size:11px;padding-left:15px; padding-right:10px;color:black;">

	<h1 style="font-family:Verdana,Arial,sans-serif;font-size:17px; font-weight:normal; color:black;">

	** This is an automated message, please do not reply **</h1>

	<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur dapibus vehicula sapien in vulputate.

	Nullam rhoncus dolor at erat faucibus scelerisque. Donec a tristique purus. Class aptent taciti sociosqu ad

	litora torquent per conubia nostra, per inceptos himenaeos. Donec eget urna sit amet ligula aliquet lacinia.

	Praesent fringilla elementum quam et vulputate. Nam bibendum, sapien sed adipiscing sodales, augue

	neque euismod tortor, eget ornare tortor justo id tellus. Fusce id lorem at nulla laoreet eleifend. Fusce odio

	diam, aliquam in semper sit amet, condimentum eget odio. Praesent dapibus urna condimentum mi

	rhoncus venenatis. Morbi ullamcorper libero in ligula tempor hendrerit. Vivamus pretium pharetra malesuada.

	Vestibulum cursus turpis eget risus ultricies faucibus eu eget urna. Donec aliquet convallis pulvinar.

	</p>

	<br />

	<br />

	</div>

	</td></tr></table>|

	Set stream = session.CreateStream

	Call stream.WriteText(sHtml)

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

	Call stream.Close

	' 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>")

	Dim rec(2) As String

	rec(0) = "kenneth.axi@lycos.com"

	rec(1) = "kenneth.axi@synergica.com"

	rec(2) = "abc@def.com"

	Dim itm As NotesItem

	Set itm = New NotesItem(doc,"Recipients","no-reply@lycos.com",NAMES)

	doc.SendTo = "no-reply@lycos.com"

	doc.BlindCopyTo = rec

	Call doc.Send(False)

	session.ConvertMime = True

	

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 clientsexternal link.

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".

 


  • Actions Show Menu▼


expanded Attachments (0)
collapsed Attachments (0)
Edit the article to add or modify attachments.
expanded Versions (6)
collapsed Versions (6)
Version Comparison     
VersionDateChanged by              Summary of changes
This version (6)Oct 1, 2012, 8:33:20 AM~Richard Zekboosilyettu  Changed the eemail-addresses to non-valid ones... getting too many tes...
5Dec 23, 2010, 2:14:49 PM~Vanessa Preponelyynds  
4Dec 23, 2010, 2:11:55 PM~Vanessa Preponelyynds  
3Dec 23, 2010, 2:09:35 PM~Vanessa Preponelyynds  Minor change
2Dec 23, 2010, 2:08:05 PM~Vanessa Preponelyynds  
1Dec 23, 2010, 2:05:16 PM~Vanessa Preponelyynds  
expanded Comments (0)
collapsed Comments (0)
Copy and paste this wiki markup to link to this article from another article in this wiki.
Go ElsewhereStay ConnectedAbout
  • HCL Software
  • HCL Digital Solutions community
  • HCL Software support
  • BlogsDigital Solutions blog
  • Community LinkHCL Software forums and blogs
  • About HCL
  • Privacy
  • Accessibility