Home > Domino Tips > Developer > HTML > Programmatically create HTML e-mails
Domino Tips:
EMAIL THIS
 TIPS & NEWSLETTERS TOPICS 

HTML

Programmatically create HTML e-mails


Angie Schottmuller
02.26.2004
Rating: -4.60- (out of 5) Hall of fame tip of the month winner


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


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.


Rate this Tip
To rate tips, you must be a member of SearchDomino.com.
Register now to start rating these tips. Log in if you are already a member.




Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


RELATED CONTENT
HTML
Trap an attachment path via the Domino file upload control field
A bevy of Notes/Domino development tips
Styling Lotus Domino Web fields
How to convert Microsoft Word or Microsoft Excel documents to HTML
An easier way to view multiple columns on the Web
How to print a form in landscape format automatically
Tip contest winner: Hide view column while being able to sort it
HTML signature maker
JavaScript autoclose window
Hide relevance score using inline style tag

HTML for Lotus Notes Domino
Trap an attachment path via the Domino file upload control field
Mimic Lotus Notes Domino application functionality on the Web
Top 10 Lotus Notes Domino programming and development tips of 2007
Creating a link on an HTML page to a Microsoft Word attachment in a Lotus Notes database
A bevy of Notes/Domino development tips
Top 10 Notes/Domino developer tips of 2006
Styling Lotus Domino Web fields
A smorgasbord of Notes/Domino development tips
An easier way to view multiple columns on the Web
How to print a form in landscape format automatically

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary

DISCLAIMER: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.



Domino & Lotus Notes Security Solutions: Authentication, Antispam, Encryption and Antivirus
HomeTopicsITKnowledge ExchangeTipsAsk the ExpertsMultimediaWhite PapersDomino IT Downloads
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides enterprise IT professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective IT purchase decisions and managing their organizations' IT projects - with its network of technology-specific Web sites, events and magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Reprints  |  Site Map




All Rights Reserved, Copyright 1999 - 2008, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts