New Response

« Return to the main article

You are replying to:

    • avatar
    • Doug Finner
    • Posted on Fri 16 Mar 2012

    So I'm a bit late to this thread and I gotta tell you that between you and Andre Giruard, you were a ton of help.

    I needed to send out a nicely formatted email that included an attachment and had a variably set of sendTo, copyTo, and blindCopyTo values. Being new to mime and not a big web buy, it's been like playing Zork...I'm still mostly in the dark but have gotten a basic framework that works.

    I've munged your code and Andre's together and post it below.



    'This code sends a mime formatted message with an attachement

    'Code adapted from Andre Giruard @ http://www-10.lotus.com/ldd/bpmpblog.nsf/dx/creating-a-mime-email-with-attachment

    'Additional help from Jake Howlett @ http://www.codestore.net/store.nsf/unid/FISR-6MQSWV?OpenDocument

    'Building a mime based message depends on the order of the mail message build

    'Turn off mime conversion

    'Set mailDoc values like subject, send to, cc, bcc

    'Create mime header

    'Attach files

    'Create plain text message body for those who don't use html mail. It's not displayed for html mail recipients

    'Create html message body for those who do use html. It's not displayed for text only mail recipients

    'Close the stream


    Dim ws As New NotesUIWorkspace

    Dim session As New NotesSession

    Dim db As NotesDatabase

    Dim QuDoSDb As NotesDatabase

    Dim QuDoSView As NotesView

    Dim formDoc As NotesDocument

    Dim deconRT As NotesRichTextItem

    Dim deconAttach As NotesEmbeddedObject

    Dim selUIDoc As NotesUIDocument

    Dim contactName As String

    'Mail variables

    Dim response As Variant 'Provide the user with an option to send mail to the customer directly or to themselves for verification first

    Dim values(1) As Variant

    Dim selDoc As NotesDocument 'Selected document

    Dim mailDoc As NotesDocument 'email with form

    Dim object As NotesEmbeddedObject

    Dim tmpFileName As String 'used to strip underscores and dashes from the original file name

    Dim rawFileName As String 'used as the 'name' in the email attachment.

    Dim attachFilename As String 'full path to the detached form

    Dim sendTo(0) As String 'If you're setting any of these to a single string value, don't declare and just put it into the mailDoc.sendTo field

    Dim copyTo(0) As String

    Dim blindCopyTo(0) as String

    'Mime variables

    Dim body As NotesMIMEEntity

    Dim mh As NotesMimeHeader

    Dim mc As NotesMIMEEntity

    Dim stream As NotesStream

    'Create the mail doc and set the initial values

    Set db = session.CurrentDatabase

    Set selUIDoc = ws.CurrentDocument

    Set selDoc = selUIDoc.Document

    Set mailDoc = New NotesDocument(db)

    session.convertMIME = False '<<<<< - important, this allows us to set the mailDoc values directly outside of the Mime process


    mailDoc.sendTo = |send to here|

    mailDoc.blindCopyTo = |bcc here|

    mailDoc.Subject= |Your subject goes here|

    rawFileName = |put what you want to display as the attachment name here|

    attachFileName = |put the fully qualified path to the file here|

    'Create the MIME headers

    Set body = mailDoc.CreateMIMEEntity

    Set mh = body.CreateHeader({MIME-Version})

    Call mh.SetHeaderVal("1.0")

    Set mh = body.CreateHeader("Content-Type")

    Call mh.SetHeaderValAndParams({multipart/alternative;boundary="=NextPart_="})

    ' create another MIME part for the attachment. (repeat as needed)

    Set mc = body.CreateChildEntity( )

    Set mh = mc.CreateHeader("Content-Disposition")

    Call mh.SetHeaderValAndParams(|attachment; filename=| & rawFileName)

    Set stream = session.CreateStream

    stream.Open attachFileName, "binary"

    Call mc.SetContentFromBytes(stream, "application/octet-stream", ENC_IDENTITY_BINARY)


    'Send the plain text part first (the code was provided as text then html but the site says html then text

    Set mc = body.createChildEntity()

    Set stream = session.createStream()

    Call stream.WriteText("Hello. I'm boring.")

    Call mc.setContentFromText(stream, {text/plain}, ENC_NONE)

    'Now send the HTML part.

    Set mc = body.createChildEntity()

    Set stream = session.createStream()

    'Create the body of the message using HTML here using the format:

    Call stream.WriteText( |Message text in HTML| )

    Call mc.SetContentFromText(stream,{text/html;charset="iso-8859-1"}, ENC_NONE)

    'Close the stream

    Call stream.close()

    'Send it

    Call mailDoc.Send(False)

    Messagebox "Form: " & rawFileName & " has been sent"

Your Comments