logo

New Response

« Return to the blog entry

You are replying to:

    • avatar
    • Sjef Bosman
    • Posted on Fri 19 Mar 2010 04:48 AM

    Hi Jake,

    I tried your code to produce a multi-part MIME newsletter, but with embedded internal images, so the mail contains all. I made some extensions, I'll post them below, but somehow I just can't get it right. Could you help me out, and at the same time expand the capabilities of the existing code? Would be great!

    Code I added as methods in the class:

    Private images() As String

    Private nimages As Integer

    Sub EmbedImage(file As String)

    Dim ContentType As String

    Dim streamFile As NotesStream

    Dim filename As String

    Redim Preserve images(nimages)

    images(nimages)= file

    nimages= nimages+1

    filename= Strrightback(file, "\")

    If Instr(file, "/") Then filename= Strrightback(file, "/")

    Me.HTML= Me.HTML + |<img src="cid:image_| & nimages & |">|

    End Sub

    Private Sub AttachImage(file As String)

    Dim ContentType As String

    Dim streamFile As NotesStream

    Dim filename As String

    Dim n As Integer

    filename= Strrightback(file, "\")

    If Instr(file, "/") Then filename= Strrightback(file, "/")

    Select Case Lcase(Strright(filename, ".") )

    Case "gif"

    ContentType = "image/gif"

    Case "jpeg", "jpg"

    ContentType = "image/jpeg"

    Case Else

    ContentType = "application/octet-stream"

    End Select

    Set Me.mc= Me.body.createChildEntity()

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

    Call Me.mh.SetHeaderVal({inline; filename="} & filename & {"} )

    'only required if we're embedding something we need to reference later on

    Set Me.mh = Me.mc.CreateHeader("Content-ID")

    n= n + 1

    Call Me.mh.SetHeaderVal( |<image_| & n & |>| )

    Set streamFile = session.CreateStream

    If streamFile.Open(file) Then

    Call Me.mc.SetContentFromBytes(streamFile, ContentType & {; name="} & filename & {"}, ENC_IDENTITY_BINARY)

    Call streamFile.Close

    End If

    End Sub

    and then in the Rebuild, I added just before the line with

    Call Me.doc.Closemimeentities(True)

    this code

    Forall image In images

    Call AttachImage(image)

    End Forall

    Here's how I use the class:

    Sub Initialize

    Dim mail As New Email()

    mail.Subject = "A multipart email generated " & Now

    mail.Sender= Split("Sjef Bosman;me@mememe.fr;TCM", ";")

    mail.Plain = "This is plain text"

    mail.HTML = "<p>This is <i>fancy</i> text</p>"

    mail.EmbedImage "c:\Windows\Cloud.gif" ' some image

    mail.HTML = mail.HTML + "<p>Woops. Forgot this</p>"

    mail.CSS = "p{margin:2em}"

    mail.Send("me@mememe.fr")

    End Sub

    If I set the output to multipart/mixed, I see the embedded image exactly where it's supposed to be. But the plain text is also there...

    Can you help me??

    Many thanks!

    Sjef

Your Comments

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