【发布时间】:2016-09-07 12:28:08
【问题描述】:
我已对此进行了严格的搜索,但无法使其正常工作。我正在尝试从 vb.net 应用程序中发送一封电子邮件,其中图像嵌入在电子邮件的正文中。我让它作为附件工作,但在 Outlook 和其他电子邮件客户端中,图像不显示。该图像存储在本地,我想知道这是否与它有关。我尝试先在字符串中添加图像,但没有成功;
emailString.AppendLine()
emailString.AppendLine()
emailString.AppendLine("<br />")
emailString.AppendLine("<br />")
emailString.AppendLine("<img src =""cid:C:\Users\Public\Pictures\Sample Pictures\br1.gif"" alt='STUPID IMAGE'>")
然后尝试使用链接资源的不同方式
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 = " <img src =""cid:C:\Users\Public\Pictures\Sample Pictures\br1.gif"">"
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
我什至将图像类型从 png 更改为 gif。将其附加到字符串时,正常的手动创建的 html 表可以工作,但上述方法不起作用。
只出现这个:
【问题讨论】:
标签: html vb.net email visual-studio-2015