为什么我的图片在附加到电子邮件时没有显示?

时间:2017-04-21 17:03:27

标签: asp.net vb.net

当用户填写表格并提交时,会向他们发送确认电子邮件。

此电子邮件附带标题图片,后面是完成表单的内容。

但是,当他们收到电子邮件时,标题图片为空白。

据我所知,没有任何安全问题。

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 />"

然后在电子邮件中,我有这个:

msg.Body = body

除图像外,所有内容都会相应显示。

任何想法我做错了什么?

1 个答案:

答案 0 :(得分:2)

将图片直接嵌入电子邮件

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>"

归功于this answer