Skip to main content
    Country/region select      Terms of use
     Home      Products      Services & solutions      Support & downloads      My account     

developerWorks  >  Lotus  >  Forums & community  >  Best Practice Makes Perfect

Best Practice Makes Perfect

A collaboration with Domino developers about how to do it and how to get it right in Domino

This question has been asked in the forums a few times and I'm not sure it's ever been adequately answered, so I thought I would show some sample code to programmatically generate the MIME content for an email body containing an attachment read from disk.

The MIME has to be multi-part, with the text being one part and each attachment being a separate part. Plug in your values in place of the parts in red.

Set result = doc.CreateMIMEEntity("Body")
Dim hdr As NotesMimeHeader
Set hdr = result.CreateHeader("Subject")
Call hdr.SetHeaderValAndParams(|Subject|)
Set hdr = result.CreateHeader("MIME-Version")
Call hdr.SetHeaderValAndParams(|1.0|)
' create multipart MIME
result.Preamble = |This is a multipart message in MIME format.

Dim tmp1 As NotesMimeEntity
Set tmp1 = result.CreateChildEntity( )
' text entity, encoding type ENC_NONE
Dim stream As NotesStream
Dim session As New NotesSession
Set stream = session.CreateStream
stream.WriteText |Message text in HTML|
tmp1.SetContentFromText stream, "text/html", ENC_NONE
' create another MIME part for the attachment. (repeat as needed)
Set tmp1 = result.CreateChildEntity( )
Set hdr = tmp1.CreateHeader("Content-Disposition")
Call hdr.SetHeaderValAndParams(|attachment; filename="filename of file to attach"|)
' application entity, encoding type ENC_IDENTITY_BINARY
Set stream = session.CreateStream
stream.Open "filepath of file to attach", "binary"
tmp1.SetContentFromBytes stream, "application/octet-stream", ENC_BINARY
tmp1.EncodeContent ENC_BASE64
' end of code to repeat per attachment.
Call doc.CloseMIMEEntities(True, "Body")

Andre Guirard | 28 May 2008 10:22:00 AM ET | Home, Plymouth, MN, USA | Comments (25)

Search this blog 


    About IBM Privacy Contact