1

When users complete their forms and submit, a confirmation email is sent to them.

This email comes with header image, followed by the contents of the form they completed.

However, when they receive the email, the header image is blank.

There is no security issue as far as I know.

Dim body As String = "<br />"
body = body & "<img src='http://doamin.com/images/banner.png' alt='' width='1177' height='267'/><br />"
body = body & " <p> Dear :  " & lblEmpName.Text & "</p><br/><p>Please DO Not reply to this email.</p><br/><p>This email confirms that your disclosure form was completed successfully </p><br /><br />Details of your disclosures are below."
body = body & " <table style ='width:70%'>"
body = body & " <td style='margin-left:20px;'><span style='font-weight:bold;'>Employee Name: </span>"
body = body & lblEmpName.Text & "</td>"
body = body & " <td><span style='font-weight:bold;'>Title: </span>"
body = body & lblPreviewTitle.Text & "</td>"
body = body & " <td><span style='font-weight:bold;'>Email: </span>"
body = body & lblPreviewEmail.Text & "</td>"
body = body & " <td><span style='font-weight:bold;'>Badge ID: </span>"
body = body & lblPreviewEmpID.Text & "</td>"
body = body & " </tr>"
body = body & " </table>"
body = body & " <hr />"

Then on the email, I have this:

msg.Body = body

Everything is displayed accordingly except the image.

Any ideas what I am doing wrong?

Kenny
  • 1,058
  • 4
  • 20
  • 49
  • Can you get to `http://doamin.com/images/banner.png` in a browser? – djv Apr 21 '17 at 17:07
  • @djv, yes, I tested it by copying it to the browser and it displays just fine. Thank you for your help. Someone downvoted me. Is it such a stupid question? It is not an off topic question. It is coding question and I posted the code. – Kenny Apr 21 '17 at 17:12
  • It is a little bit of a "why isn't this code working?" question. I don't think it's worth closing however. As to your question: can you check the `body` string when it's set to the message? You should be able to just put that in an HTML document in visual studio and preview what it will look like. – djv Apr 21 '17 at 17:18
  • @djv, thank you. The values you see there are displayed correctly except the image. – Kenny Apr 21 '17 at 17:22
  • If you put this in there in place of your image, does it work? `` – djv Apr 21 '17 at 17:33
  • No, it is still showing the same blank image. Thanks for your help. – Kenny Apr 21 '17 at 17:44
  • In an HTML file in visual studio? That would be strange as this is just Google's logo. Unless you are behind a firewall... – djv Apr 21 '17 at 18:11
  • Yes, you are correct. I am behind a firewall. The strange about the image I am using though is that it is inside the firewall. I didn't realize that sending content with image header would be problematic. By the way, I have done something similar where users would complete a form and upon submit, would receive email confirmation with company logo displaying. Why then are we able to receive emails with image header showing? – Kenny Apr 21 '17 at 18:43
  • Instead of linking to it, you could just embed it in the email. It would equate to more network traffic but might overcome your issue. See http://stackoverflow.com/a/19139042/832052 for an example. – djv Apr 21 '17 at 19:05
  • Should "doamin.com" be spelled "domain.com"? – JohnH Apr 21 '17 at 19:07
  • @JohnH, no. I did that to mask the actual name. – Kenny Apr 21 '17 at 19:17
  • Are you able to examine the raw HTML of the generated email? If you send the email to a Gmail account you could use Chrome's Inspect function to examine the HTML in the email. That may show why the image does not appear. – JohnH Apr 21 '17 at 19:22
  • @djv, YEA, your persistence and patience paid off. That link worked beautifully. Thank you. I will like to credit you for this please. John, thanks too for contributing. – Kenny Apr 21 '17 at 19:37

1 Answers1

2

Embed the image directly into the email

Dim msg As MailMessage
msg.IsBodyHtml = True
Dim inlineLogo = New Attachment("C:\Desktop\Image.jpg")
msg.Attachments.Add(inlineLogo)
Dim contentID As String = "Image"
inlineLogo.ContentId = contentID
inlineLogo.ContentDisposition.Inline = True
inlineLogo.ContentDisposition.DispositionType = DispositionTypeNames.Inline
msg.Body = "<htm><body> <img src=\""cid:" & contentID & "\""> </body></html>"

Credit to this answer

Community
  • 1
  • 1
djv
  • 15,168
  • 7
  • 48
  • 72