Send email with 2 embedded images

J Trahair

Well-known member
Joined
May 14, 2008
Messages
175
Location
Spain
Programming Experience
10+
Hi. The following code will successfully send an email with one embedded image (the second image 'cid') as a footer. The variable strEmailText contains the text of the email:

VB.NET:
        Dim cid1 As String = email.AddRelatedFile(mstrAppPath & "Company header.png")
        Dim cid As String = email.AddRelatedFile(mstrAppPath & "Company footer.png")
        If cid Is Nothing Then
            MessageBox.Show(email.LastErrorText)
        End If

        'Update the HTML to reference the image using the CID:
        Dim htmlBody As String = "<html><body><font color=" & Chr(34) & "#000000" & Chr(34) & " size=" & Chr(34) & "3" & Chr(34) & " face=" & Chr(34) & "Times New Roman" & Chr(34) & ">" & "<img src=""cid1:IMAGE_CID1""><br>" & strEmailText & "<br><img src=""cid:IMAGE_CID"">"
        htmlBody = htmlBody.Replace("IMAGE_CID1", cid1)
        htmlBody = htmlBody.Replace("IMAGE_CID", cid)
        'htmlBody = htmlBody & "</font><br><br><font color=" & Chr(34) & "#1C489C" & Chr(34) & " size=" & Chr(34) & "1" & Chr(34) & " face=" & Chr(34) & "Calibri" & Chr(34) & ">" & strEmailTextFooter & "</font></body></html>"

        'Set the basic email stuff: HTML body, subject, "from", "to"
        email.SetHtmlBody(htmlBody)
(I have omitted the From's and To's, as well as the actual sending code.) I am trying to get the image 'Company header.png' to sit at the top of the email message, but this image is attached as an attachment, but with a small 'no-image-file-found' image in the correct position at the top of the message area. The 'Company footer.png' is embedded as required at the bottom of the email message.

How can I get an embedded image at the top as well? (With the email text between the two imsgaes?)

Thanks in advance.
 

Latest posts

Back
Top