Hi,
I have a requirement to send notes rich text emails with HTML style links and inline images.
No file attachments should show within the mail body, yet the images need to be visible when the user is offline.
After searching for similar topics both here and in google, it seemed a good way to tackle this might be to use the NotesMIMEEntity class together with a NotesStream to do so.
I got the html part working fine, but I’m having real problems getting images to appear.
FYI the emails are being created on the fly by a scheduled LS agent, and I can’t make mods to the mail template. My code is below. If anyone could offer me some advice I’d be really grateful. I’m afraid I haven’t been able to find many examples of inline MIME images on the web…
Sub Initialize
Dim s As New NotesSession
Dim db As NotesDatabase
Dim doc As NotesDocument, formatDoc As NotesDocument
Dim body As NotesMIMEEntity, mimeImage As NotesMIMEEntity, mimeText As NotesMimeEntity
Dim header As NotesMimeHeader, mimeHeader As NotesMIMEHeader
Dim stream As NotesStream
Set db = s.CurrentDatabase
s.ConvertMIME = False ' Do not convert MIME to rich text
Set doc = db.CreateDocument
doc.Form = "Memo"
doc.Subject = "Newsletter MIME Test"
doc.Principal = "Newsletter Team"
Set body = doc.CreateMIMEEntity
’ Create main MIME message
Set stream = s.CreateStream
Set header = body.CreateHeader("MIME-Version")
Call header.SetHeaderVal("1.0")
Set header = body.CreateHeader("Content-Type")
Call header.SetHeaderValAndParams(|multipart/related;boundary="*_bounds_*"|) ' Parts are components of a single document (for example, an HTML page and the images in that page).
’ Create Message text
Set mimeText = body.CreateChildEntity
Call stream.WriteText(|<style>TD {font-family:arial;font-size:9pt;}</style><table width="100%" border="0" cellspacing="0">| &_
|<tr><td>Image Link</td><td>|)
Call stream.WriteText(|<a href="http://www.lotus.com">Lotus Website</a>| &_
|<img src="cid:-*msg.LotusImage*-" alt="Lotus" width="240" height="30"></td></tr></table>|)
Call mimeText.SetContentFromText(stream,"text/html;charset=iso-8859-1",ENC_QUOTED_PRINTABLE)
’ Create inline image reference
Set mimeImage = body.CreateChildEntity
Set mimeHeader = mimeImage.CreateHeader("Content-ID")
Call mimeHeader.SetHeaderVal("-*msg.LotusImage*-")
Set mimeHeader = mimeImage.CreateHeader("Content-Disposition")
Call mimeHeader.SetHeaderValAndParams("inline;filename=c:\documents and settings\ghinton\desktop\km newsletters\images\db_monitor_industries.gif")
Call mimeImage.SetContentFromBytes(stream, "image/gif",ENC_IDENTITY_BINARY)
’ Call body.SetContentFromText(stream, “text/html”, ENC_NONE) ’ think this is what I’m getting wrong??
’ Call stream.Truncate ’ deletes the stream object from memory
Call doc.Send(False, "Giles Hinton")
s.ConvertMIME = True ' Restore conversion
End Sub