This code work for me in LotusScript(but i dont test with pictures), try it. Rewrite it for ssjs/java if you need or use 'Run with document context' agent.
This code create mail with mime 'body' with attachment and append other mime element. Sorry for dirty code. I hope I could help you.
Private Function CreateMessage( xDoc As NotesDocument, xFrom As String, xSendTo As Variant, xSubject As String, xBodyHTML As String, xFilepath As String ) As NotesDocument
On Error GoTo Except
Dim mail As NotesDocument
Dim body As NotesMIMEEntity, bodyChild As NotesMIMEEntity, header As NotesMIMEHeader
Dim stream As NotesStream
Dim link As String
Dim convertMime As Boolean
convertMime = CommonTools_Session.Convertmime
CommonTools_Session.Convertmime = False
Set mail= CommonTools_GetSystemMailBox.CreateDocument
res.ReplaceItemValue "Form", "Memo"
res.ReplaceItemValue "PostedDate", CDat(Now)
res.ReplaceItemValue "From", xFrom
res.ReplaceItemValue "Subject", xSubject
res.ReplaceItemValue "SendTo", xSendTo
res.ReplaceItemValue "Recipients", xSendTo
Set body = mail.CreateMIMEEntity("Body")
Set header = body.CreateHeader("Content-Type")
Call header.SetHeaderValAndParams(|multipart/mixed; boundary="boundary-example-1"; type=text/html|)
Set stream = CommonTools_session.CreateStream
If xFilepath <> "" Then
Set bodyChild = body.Createchildentity()
Call bodyChild.SetContentFromText( stream, "text/html; charset=windows-1251", ENC_NONE )
Call stream.Truncate()
If stream.Open( xFilepath ) Then
Set bodyChild = body.Createchildentity()
Set header = bodyChild.Createheader( "Content-Disposition" )
Call header.Setheaderval( {attachment; filename="Meeting minutes.xls"; charset=windows-1251} )
Call bodyChild.Setcontentfrombytes( stream, "application/vnd.ms-excel", ENC_NONE )
Call stream.Close()
Call stream.Truncate()
xBodyHTML = "<br><br>" + xBodyHTML
Else
Error 5001, "Cannot open file"
End If
End If
Dim mime As NotesMIMEEntity
Set mime = xDoc.Getmimeentity( "MM_BodyAgenda" )
If Not mime Is Nothing Then
Set bodyChild = body.Createchildentity()
Call bodyChild.Encodecontent( ENC_NONE )
Call appendMimeToBody( mime, bodyChild )
End If
Call stream.WriteText( "<br><br>" + link + "<br><br>" + xBodyHTML + "<br>" + link + "<br><br>", EOL_NONE )
Set bodyChild = body.Createchildentity()
Call bodyChild.SetContentFromText( stream, "text/html; charset=windows-1251", ENC_NONE )
Call mail.CloseMIMEEntities( True, "Body" )
Set CreateMessage = mail
CommonTools_Session.Convertmime = convertMime
End Function
Sub appendMimeToBody( xMime As NotesMIMEEntity, xBody As NotesMIMEEntity)
Dim ct, cst, thisname, hn, hv, thishead
ct = xMime.ContentType
cst = xMime.ContentSubType
Dim encoding As Integer
encoding = xMime.Encoding
Dim stream As NotesStream
Dim ttCharset As String
ttCharset = "utf-8"
thisname = "" ' name of file if this part is an attachment
ForAll header In xMime.HeaderObjects ' handles Subject and other headers
hn = header.HeaderName
If hn="Content-Type" Then
thisname = header.GetParamVal("name") ' could be filename
End If
If Not (hn="Content-Type" Or hn="X-Notes-Item" ) Then ' don't pass X-Notes-Item '
hv = header.GetHeaderValAndParams
Set thishead = xBody.CreateHeader(hn)
Call thishead.SetHeaderValAndParams(hv)
End If
End ForAll
If ct="multipart" Then
Set thishead = xBody.CreateHeader("Content-Type")
Call thishead.SetHeaderVal(ct+"/"+cst + {; charset="} + ttCharset + {"; boundary="boundary-example-1} + "qqqqwerty" + {"} )
xBody.Preamble = xMime.Preamble
Dim child As NotesMIMEEntity
Dim outchild As NotesMIMEEntity
Set child = xMime.GetFirstChildEntity
Do While Not child Is Nothing
Set outchild = xBody.CreateChildEntity
Call doPart(child, outchild)
Set child = child.GetNextSibling
Loop
Else ' pass unchanged
Set stream = CommonTools_Session.CreateStream
Call xMime.GetContentAsBytes(stream, False)
Dim s As String
s = stream.ReadText()
Dim b As Variant
b = stream.Read()
If Trim(thisname)="" Then
If ct = "text" And cst = "html" Then Call stream.Writetext( "<br><br><br>" )
Call xBody.SetContentFromBytes(stream, ct+"/"+cst+{;charset="} + ttCharset + {"}, encoding)
Else
Call xBody.SetContentFromBytes(stream, ct+"/"+cst+{;charset="} + ttCharset + {";name=}+thisname, encoding)
End If
End If
End Sub