embedding image in body of email from vb.net
<p>I have rigorously searched for a soln on this but cannot get this to work. I am trying to send an email from within a vb.net application where an image is embedded in the body of the email. I get it to work as an attachment but in outlook and other email clients, the image does not show. The image is stored locally and I wonder if that has anything to do with it. I tried adding the image within a string first and that did not work;</p>

<pre><code>    emailString.AppendLine()
    emailString.AppendLine()
    emailString.AppendLine("&lt;br /&gt;")
    emailString.AppendLine("&lt;br /&gt;")
    emailString.AppendLine("&lt;img src =""cid:C:\Users\Public\Pictures\Sample Pictures\br1.gif"" alt='STUPID IMAGE'&gt;")
</code></pre>

<p>then tried a different way with linkedresource</p>

<pre><code>  Sub SendEmail(ByVal errorMessage As String)
    Dim mail As New MailMessage()
    mail.From = New MailAddress("med@person.com", "**DAILY STATS**")
    mail.Subject = "STATS ALERT"
    mail.To.Add("med@person.com")
    mail.IsBodyHtml = True
    'mail.Body = "TEST EMAIL" 'errorMessage
    'mail.BodyEncoding = Encoding.UTF8
    smptpServer.Timeout = 30000
    smptpServer.Credentials = New NetworkCredential("me", "person")
    Dim imageBody As String = " &lt;img src =""cid:C:\Users\Public\Pictures\Sample Pictures\br1.gif""&gt;"
    Dim htmlView As System.Net.Mail.AlternateView = System.Net.Mail.AlternateView.CreateAlternateViewFromString(errorMessage, Nothing, "text/html")
    Dim plainTextView As System.Net.Mail.AlternateView = System.Net.Mail.AlternateView.CreateAlternateViewFromString(errorMessage, Nothing, "text/plain")
    Dim imageResource As New System.Net.Mail.LinkedResource("C:\Users\Public\Pictures\Sample Pictures\br1.gif", MediaTypeNames.Image.Gif)
    Dim attachment As System.Net.Mail.Attachment
    attachment = New System.Net.Mail.Attachment("C:\Users\Public\Pictures\Sample Pictures\br1.gif")
    mail.Attachments.Add(attachment)


   'imageResource.ContentId = "HDIImage"
    htmlView.LinkedResources.Add(imageResource)
    htmlView.TransferEncoding = Net.Mime.TransferEncoding.Base64
    htmlView.ContentType = New System.Net.Mime.ContentType("text/html")
   'mail.AlternateViews.Add(plainTextView)
    mail.AlternateViews.Add(htmlView)
    Try
        smptpServer.Send(mail)




    Catch ex As Exception
        If ex.Message.Contains("Timeout") Then
           Exit Sub
        End If
    End Try
</code></pre>

<p>I even changed the image type from png to gif. The normal manually created html tables work when appending it to the string but this above way does not work.</p>

<p>Only this appears:</p>

<p><a href="https://i.stack.imgur.com/Nhmzg.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Nhmzg.png" alt="enter image description here"></a></p>