views:

64

answers:

3

While trying to use the hints in your answer at

http://stackoverflow.com/questions/686384/sending-formatted-lotus-notes-rich-text-email-from-excel-vba

I could do almost everything I needed: write multiple lines with data from a database of mine, formatting the body by mean of html code, with links and formatted text.

I also need to put an image in the mail body, but the html code "img src="etc. does not work, maybe because the image is located on my pc and is not reached by the recipients. I need to find a way to embed the image just like I would do by mean of the Lotus menus. In my Italian Lotus Notes 7, there is a Create menu with an Image option, I find the image, click OK and it is done.

That's what I wish to do with my code, please tell me it's possible! :-)

Thanks in advance.

Riccardo Baldinotti, Italy

A: 

Here you can find the complete code. It's too large to paste here, so I'm copying just a few lines to show the idea:

  If (bSetImages) Then
        For iImageIndex = 0 To Ubound(imageFilePaths)

              ' Get the image file path and content id (cid).
              strImagePath = Trim(imageFilePaths(iImageIndex))
              If (strImagePath = "") Then Exit Sub
              strImageCid = Trim(imageContentIds(iImageIndex))
              If (strImageCid = "") Then Exit Sub

              ' Get the image context type.
              If (StrContains(strImagePath, ".", True)) Then strImageExt = Strrightback(strImagePath, ".") Else strImageExt = ""
              Select Case Lcase(strImageExt)
              Case "gif":      strImageType = "image/gif"
              Case "jpg":      strImageType = "image/jpg"
              Case Else:      strImageType = "image/gif"
              End Select

              ' Add the image part.
              Set mimeImage = mimeBody.CreateChildEntity()
              Set mimeImageHeader = mimeImage.CreateHeader({Content-ID})
              Call mimeImageHeader.SetHeaderVal("<" & strImageCid & ">")
              Call stream.Open(strImagePath)
              Call mimeImage.SetContentFromBytes(stream, strImageType & {;name="} + strImageCid + {"}, ENC_IDENTITY_BINARY)
              Call stream.Close()

        Next
  End If
belisarius
I can only add the image as an attachment. The code is in the next answer.
Riccardo Baldinotti
A: 

I only have one image to add, but the following sub just gives me the html text, as if I did no add the image lines

    Dim subject As String
    Dim Maildb As Object
    Dim UserName As String
    Dim MailDbName As String
    Dim MailDoc As Object
    Dim Session As Object
    Dim body As Object
    Dim stream As Object
  Dim strImagePath As String
  Dim strImageType As String
  Dim strImageCid As String
  Dim mimeImage As Object
  Dim mimeImageHeader As Object
    Set Session = CreateObject("Notes.NotesSession")
    UserName = Session.UserName
    MailDbName = Left$(UserName, 1) & Right$(UserName, (Len(UserName) - InStr(1, UserName, " "))) & ".nsf"
    Set Maildb = Session.GETDATABASE("", MailDbName)
    If Maildb.ISOPEN = True Then
    'Already open for mail
    Else
        Maildb.OPENMAIL
    End If
    Set MailDoc = Maildb.CREATEDOCUMENT
    MailDoc.Form = "Memo"
    Dim mimeHTML As Object
    Set stream = Session.CreateStream()
    Set body = MailDoc.CreateMIMEEntity
    subject = "Newsletter direzionale"
    Set mimeHTML = body.CreateChildEntity()
    Call stream.WriteText(fFaiPagina) produces the html body of the message.
    Call mimeHTML.SetContentFromText(stream, "text/html;charset=iso-8859-1", ENC_IDENTITY_8BIT)
    Call stream.Close
    strImagePath = CurrentProject.path & "\ico_world.gif"
    strImageCid = "ico_world.gif"
    strImageType = "image/gif"
    Set mimeImage = body.CreateChildEntity()
    Set mimeImageHeader = mimeImage.CreateHeader("Content-ID")
    Call mimeImageHeader.SetHeaderVal("<" & strImageCid & ">")
    Call stream.Open(strImagePath)
    Call mimeImage.SetContentFromBytes(stream, strImageType & ";name='" + strImageCid + "'", ENC_IDENTITY_BINARY)
    Call stream.Close
    Dim mandali As String
    mandali = "Riccardo Baldinotti/Regione_Lombardia" a test message, sent to myself
    MailDoc.sendto = mandali '
    MailDoc.subject = subject
    MailDoc.returnreceipt = "0"
    MailDoc.SAVEMESSAGEONSEND = True
    MailDoc.PostedDate = Now()
    MailDoc.Send 0, mandali

Many thanks.

Riccardo Baldinotti
A: 

At the address

http://www-10.lotus.com/ldd/nd6forum.nsf/DateAllThreadedweb/dcbf91b97004f0af8525773e002867a9?OpenDocument

I found a solution, and now my mail body has an image in it.

Here is my code.

Call stream.Open("")

Set body = MailDoc.CreateMIMEEntity '("memo")

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

Call richTextHeader.SetHeaderVal("multipart/mixed")

Set mimeImage = body.CreateChildEntity()

strImageType = "image/jpeg" 'Other formats are "image/gif" "image/bmp"

Call mimeImage.SetContentFromBytes(stream, strImageType, ENC_IDENTITY_BINARY)

Call stream.Close

Regards

Riccardo Baldinotti