Send Notes mail from an XML call

The other function called from the “doMail” function is the “doAttachFile” function which populates our Body field and attaches any attachments that are present.

Function doAttachFile(s As NotesSession, docMail As NotesDocument) As Boolean
    On Error Goto errorCatch
    Dim stream As NotesStream
    Set stream = s.CreateStream
    Dim body As NotesMimeEntity, bodyChild As NotesMimeEntity
    Dim header As NotesMimeHeader
    Dim x As Integer
    doAttachFile = False
    Set body = docMail.CreateMIMEEntity("Body")
    Call stream.WriteText(strMailBody + Chr$(13) + Chr$(13))
    Set bodyChild = body.CreateChildEntity()
    Call bodyChild.SetContentFromText(stream,"",ENC_NONE)
    Call stream.Close
    Call stream.Truncate
    For x = 0 To Ubound(arrFileName)
        Call stream.WriteText(arrMime64(0))
        Set bodyChild = body.CreateChildEntity()
        Set header = bodyChild.createHeader("Content-Type")
        Call header.setHeaderVal("multipart/mixed")
        Set header = bodyChild.createHeader("Content-Disposition")
        Call header.setHeaderVal("attachment; filename=" & arrFileName(x))
        Set header = bodyChild.createHeader("Content-ID")
        Call header.setHeaderVal(arrFileName(x))
        Call bodyChild.SetContentFromText(stream, arrContentType(x), ENC_BASE64)
        Call stream.Close
        Call stream.Truncate
    Next
    doAttachFile = True
    Exit Function
errorCatch:
    strOut = "Error in doSendMessage:doAttachFile in line: " & Erl() & " error$: " & Error$
    doAttachFile = False
    Exit Function
End Function

Each attachment is a child entity to the main MIMEentity, and they are all attached after the global “strMailBody” variable.

So there it is, a relatively simple way for any application that can talk XML to send an e-mail. The entire agent wrapped into a Domino DB is here. Next I’ll cover a simple way to use XML to grab directory names from multiple directories using partial last name matches. This can be done with LDAP also, but there is alot more simplicity in using straight XML for that.

Happy Hunting!!

Pages: 1 2 3 4 5

One Response to “Send Notes mail from an XML call”

  1. nick wall Says:

    Hi there. Came across this article via codestore http://www.codestore.info/store.nsf/unid/BLOG-20060329, via Johan Känngård http://johankanngard.net/2005/12/13/sending-html-mails-via-lotusscript/ then you!

    We have a PC on our network, that is used to run an Excel program, the Excel file is then emailed to various users (they should really stick it in a central repository etc…). The sending user could log into their Web Access mail file, but as an interesting exercise, I would like to give this a go. I keep getting a 404 error when trying to download your sample database.

    Great site, interesting articles.

    Nick