Send newsletter HTML Email with pictures as body

Viewed 23

I'm new to this group and i have one question. how can i attach pictures on the HTML newsletter that i have. when i send the newsletter everything goes well but the pictures are not showing on the email. please help. this is the code.

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

    Dim Body As String = GetWebPageContent(Sender_email, Message)
    Dim Mail As New MailMessage
    Mail.Subject = "Test HTML"
    Mail.To.Add(to_email)
    Mail.From = New MailAddress(Sender_email)
    Mail.Body = Body
    Mail.IsBodyHtml = True
    Mail.Priority = MailPriority.Normal
    Dim SMTP As New SmtpClient(SMTP_Confg)
    SMTP.EnableSsl = False
    SMTP.Credentials = New System.Net.NetworkCredential(Sender_email, Password)
    SMTP.Port = Port_Num
    Try
        SMTP.Send(Mail)
        MsgBox("Successfully Sent!!!")
    Catch ex As Exception
        MessageBox.Show(" - your confermation email is not sent! " & vbNewLine & " Please contact your Administrator!")
    End Try
End Sub

Private Function GetWebPageContent(ByVal recipient As String, ByVal customMsg As String) As String
    Dim objStreamReader As New StreamReader("C:\Users\alex.GFH\Desktop\Email\beefree-s09uuvnlono.HTML")
    'read html template file'
    Dim bodyMsg As String = objStreamReader.ReadToEnd()
    Return bodyMsg
End Function
1 Answers

It looks like you're copying the raw HTML from this file:

"C:\Users\alex.GFH\Desktop\Email\beefree-s09uuvnlono.HTML"

As the message body of your email.

My psychic powers tell me that you've got <img> tags inside your HTML that are pointing to relative locations. e.g. <img src="picture.jpg"/>. As such when the HTML email is opened in someone else's browser or mail app, the renderer has no idea where to fetch "picture.jpg" from.

And even if it did have the full URL, most mail apps won't fetch URL images by default until the user acknowledges the privacy risk.

I think if you want your images to just show up when the mail is opened, inline the image bytes directly into the <img> tag. You base 64-encode the image and stick on a header (e.g. data:image/png;base64, or data:image/jpeg;base64,. That becomes the src attribute.

E.g: <img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==" alt="Red dot" />

More details here: https://www.rfc-editor.org/rfc/rfc2397

Related