View member feedback to this tip.
Editor's Note: This tip only works in ND6. This code uses the NotesMIMEEntity class, so it only works with Release 5.0.2 and above.
Have you wondered how e-marketing campaigns create those swanky advertisements using HTML? Some folks think the only way to do that in Notes is to store the form in the document or insert a bunch of images. However, that cannot be done programmatically, and stored forms and images make for large file sizes. Here's how you can create awesome HTML e-mails in Notes by rending the message body as MIME instead of Rich Text.
Code
Copy the following code into a LotusScript agent. Be sure to change the sendto or the e-mail will go to me. Run the agent and see how the HTML appears. Update the code as needed. When I use the code I create subs for writing the stylesheet and all the content. Have fun!
Sub Initialize
'Declare Variables
Dim s As New NotesSession
Dim db As NotesDatabase
Dim body As NotesMIMEEntity
Dim stream As NotesStream
Dim host As String
Set db = s.CurrentDatabase
'Capture the server name and filepath
for use in URLs
Dim ServerName As New NotesName
( db.Server )
host = "http://" + ServerName.Common
& ".imation.com"
s.ConvertMIME = False ' Do not convert
MIME to rich text
Set stream = s.CreateStream
'Begin creating the message doc to send
Dim message As New NotesDocument (db)
message.Form="memo"
Set body = message.CreateMIMEEntity
'Basic profile of email
message.Subject = "Sample HTML
email via MIME"
message.SendTo = "aschottmuller@imation.com"
message.RecNoOutOfOffice = "1"
'Set it so out of office agents don't reply t
o the
message
' Open the HTML (Title doesn't matter since
it doesn't appear anywhere)
Call stream.WriteText ("<html>
<head><title>Sample HTML
email via MIME</title>")
' BEGIN: Inline Stylesheet
Call stream.WriteText (|
<style type="text/css">
<!--
.text, td, tr, p, br, body {
COLOR: #666666;
FONT-FAMILY: Arial, Helvetica, sans-serif;
FONT-SIZE: 12px;
}
a {
font-family: Arial, Helvetica, sans-serif;
color: #663399;
FONT-WEIGHT: bold;
text-decoration: none;
}
-->
</style>
|)
' END: Inline Stylesheet
Call stream.WriteText ({</head>})
Call stream.WriteText ({<body text="#666666"
bgcolor="#FFFFFF"
leftmargin="0"
topmargin="0" marginheight="0"
marginwidth="0">})
' BEGIN: HTML body
Call stream.WriteText ({
<table width="100%" border="0"
cellspacing="0" cellpadding="0"
bgcolor="#FFFFFF">
<tr>
<td>Here is the MIME content!<br>
<br>
<b>Notes:</b>
<ul>
<li>MIME emails require absolute URLs
on all images and hrefs<li>
<li>HTML can easily be copied directly
from an editor to the LotusScript -
})
Call stream.WriteText ("use pipes (|) and curly
brackets ({}) to get around the
quote issue.<li>")
Call stream.WriteText ({<li>Stylesheets
must be inline vs. linked. (iNotes will override
the stylesheet)<li>
<li>Notes will NOT render table background
images, but colors WILL properly
display<li>
<li>Notes will not properly render table rows
with a height smaller than the default
text.<li>
</ul>
<br>Visit <a href=http://searchdomino.techtarget.com>
SearchDomino.com</a> for more
exciting tips or visit
<a href=http://www.imation.com>Imation</a>
for the coolest data storage
products
around!<br><br>
<a href=http://searchdomino.techtarget.com>
<img src=http://searchdomino.techtarget.com/searchDomino/images/header_logo.gif
width="198" height="33"></a>
</td>
</tr>
</table>
})
' END: HTML body
' Close the HTML
Call stream.WriteText
({</body></html>})
' Ensure the MIME content will be recognized as
HTML (Must be after the
stream is written)
Call body.SetContentFromText (stream,
"text/html;charset=iso-8859-1",
ENC_NONE)
'Send the email
Call message.Send (False)
s.ConvertMIME = True ' Restore conversion
End Sub
MEMBER FEEDBACK TO THIS TIP
Very good find, it's just what I was looking for, but it doesn't work on R5. The NotesMIMEEntry class doesn't exist in R5.
-- Alain G.
****************************************************
This is much better solution for R6 than the quirky work-arounds that were necessary in R5. I have always preferred HTML to Rich Text formatting. This tip makes it easy. Great tip!
-- Chris C.
****************************************************
Excellent tip! I've been looking at HTML e-mails and you just saved me quite a bit of trouble.
-- Paul M.
****************************************************
Angie, you must have been listening to my last conversation! I now have a REAL reason to upgrade to ND6+. Works like a dream.
--Ralph R.
****************************************************
In this tip Angie has this line:
message.RecNoOutOfOffice = "1"
I did a Google search and did not find any information on this. Is this a standard to prevent out of office agents from sending an e-mail?
Also, I send out HTML e-mails by creating a database that has "control" documents. In my LotusScript agent I copy the body of the control document (which has the message I want to send). The Domino 6 router (R5 does not do this) will convert the Notes Rich Text formatting to HTML and send out a MIME message. This way you do not have to write the HTML/MIME and the plain text. Domino sends out a message with both the MIME/HTML and plain text and the receiving mail server chooses which version to use.
-- Howard G.
******************************************
This article just made me look fantastic to my new (2 weeks) boss.
Thank you so much!
Michael K.
******************************************
Is there a way to extract the raw HTML from the Body field of a NotesDocument? For example, If I receive an e-mail from another domain, such as Yahoo!,which is stored in the nsf file in HTML format, is there a way to extract this raw HTML out using LotusScript? Also, is there a way to convert RichText into HTML?
Abhijeet P.
Do you have comments of your own? Let us know.