如何以HTML格式在邮件上附加图像 [英] How to attach a image on mail in HTML format
本文介绍了如何以HTML格式在邮件上附加图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的应用程序中,通过gmail发送打印票时,它没有在邮件中显示我的徽标图片(jpeg)..为什么请帮助我,先生...!
In my application while sending the printticket on gmail, it didnt show my logo image(jpeg) on the mail..why please help me sir...!
推荐答案
您必须同时使用备用视图和链接资源,才能将图像嵌入到电子邮件中.
You have to make use of a combination of both Alternate Views and Linked resources in order to embed images in e-mail.
Imports System.Net.Mail
Imports System.Net.Mime
Public Class EmailMessage
Sub New(ByVal body As String, ByVal isHtml As Boolean, Optional ByVal subject As String = DefaultSubject)
p_messagesubject = subject
Message.Subject = MessageSubject
Message.Priority = MailPriority.High
Message.IsBodyHtml = isHtml
If isHtml Then
p_htmlmessagebody = body
Dim htmlContent As ContentType
htmlContent = New ContentType("text/html")
Dim htmlView As AlternateView
htmlView = AlternateView.CreateAlternateViewFromString(HtmlMessageBody, Nothing,
MediaTypeNames.Text.Html)
Dim logo As LinkedResource = New LinkedResource("c:\mylogo.jpg")
logo.ContentId = "MyEmbeddedLogo"
logo.TransferEncoding = System.Net.Mime.TransferEncoding.Base64
htmlView.LinkedResources.Add(logo)
Message.AlternateViews.Add(htmlView)
Else
p_messagebody = body
Message.Body = MessageBody
End If
End Sub
End Class
现在,为了显示徽标,您必须在HtmlMessageBody中具有标准的HTML img标签,其src属性设置为ContentId的名称
Now, in order for the logo to show up you have to have a standard HTML img tag inside the HtmlMessageBody whose src attribute is set to the name of the ContentId
<img src="cid:MyEmbeddedLogo" />
您可以使用"System.Net.Mail.LinkedResource"来完成这项工作.
使用ASP.NET嵌入电子邮件中的图像 [ ^ ]对于您的解决方案将是不错的文章.
--Amit
Hi,
You can use "System.Net.Mail.LinkedResource" to do the job.
Embed an Image in Email using ASP.NET[^] would be a nice article for your solution.
--Amit
这篇关于如何以HTML格式在邮件上附加图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文