logo

New Response

« Return to the blog entry

You are replying to:

  1. Here is the simple way to attach (and base64 encode) a file to MIME.

    Function MimeAttachFileAsBase64(mime As NotesMimeEntity, sFolderPath As String, sFileName As String) As Boolean

    On Error Goto ERRHANDLER

    Dim sess As New NotesSession

    Dim nsFile As NotesStream

    Dim mimeChild As NotesMimeEntity

    Dim mimeheader As NotesMimeHeader

    Dim sContentType As String

    MimeAttachFile = False

    Set nsFile = sess.CreateStream()

    If Not nsFile.Open(sFolderPath & sFileName, "Binary") Then

    Print "MimeAttachFileAsBase64 Error: Failed to open file: " & sFolderPath & sFileName

    Err = 0

    Exit Function

    End If

    Set mimeChild = mime.CreateChildEntity()

    sContentType = |application/octet-stream| ' application/octet-stream is a default value

    Call mimeChild.SetContentFromBytes( nsFile, sContentType & |; name="| & sFileName & |"|, ENC_NONE)

    ' base64 encode the file

    Call mimeChild.EncodeContent( ENC_BASE64)

    ' Content-Disposition header

    Set mimeheader = mimeChild.createHeader("Content-Disposition")

    Call mimeheader.SetHeaderVal(|attachment; filename="| & sFileName & |"|)

    ' close stream and cleanup

    Call nsFile.Close()

    Set nsFile = Nothing

    MimeAttachFile = True

    Exit Function

    ERRHANDLER:

    Print "MimeAttachFileAsBase64 Error: " & Format$(Err) & " " & Error & " # Line: " & Format$(Erl)

    Err = 0

    Exit Function

    End Function

Your Comments

Name:
E-mail:
(optional)
Website:
(optional)
Comment: