To send HTML mails in R6, you have to use the setContentFromText method in the NotesMIMEEntity class. To add inline images, use the setContentFromBytes method in the same class, like this:
Dim session as New NotesSession()
session.convertMIME = False ' Do not convert to rich text
Dim currentDb As NotesDatabase
Set currentDb = session.currentDatabase
Dim path As String
path = "c:\temp\test.html"
Dim message As NotesDocument
Set message = currentDb.createDocument()
Call message.replaceItemValue("Form", "memo")
Call message.replaceItemValue("From", "[email protected]")
Call message.replaceItemValue("Subject", _
"HTML email via MIME")
Call message.replaceItemValue("SendTo", "[email protected]")
Dim body As NotesMIMEEntity
Set body = message.CreateMIMEEntity
Dim mh As NotesMimeHeader
Set mh = body.CreateHeader({MIME-Version})
Call mh.SetHeaderVal("1.0")
Set mh = body.CreateHeader("Content-Type")
Call mh.SetHeaderValAndParams( _
{multipart/related;boundary="=NextPart_="})
Dim mc As NotesMIMEEntity
Set mc = body.createChildEntity()
Dim stream As NotesStream
Set stream = session.createStream()
If Not stream.open(path, "ISO-8859-1") Then
Error 2000, "Could not open file"
End If
Call mc.setContentFromText(stream, _
{text/html;charset="iso-8859-1"}, ENC_NONE)
Call stream.close()
Call addImage(body, "C:\temp\image1.gif")
Call addImage(body, "C:\temp\image2.gif")
Call message.send(False)
The addImage method looks like this:
Public Sub addImage(body As NotesMimeEntity, _
imagePath As String)
Dim id As String
Dim stream As NotesStream
Dim mh As NotesMimeHeader
Dim mc As NotesMIMEEntity
id = Strrightback(imagePath, "\")
Set stream = session.createStream()
Set mc = body.createChildEntity()
Set mh = mc.createHeader({Content-ID})
Call mh.setHeaderVal(id)
Call stream.open(imagePath)
Call mc.setContentFromBytes(stream, _
"image/gif;name=""" + id + """", ENC_IDENTITY_BINARY)
Call stream.close
End Sub
The HTML code must refer to the images via URL:s containing cid and the “path” to the image, like this:
<img src="cid:imagename.gif" />
Found this great tip via LDD, posted by Raymond Neeves.