[英]Sending HTML email containing images in mail body VB.NET
I am working on a Mail App in VB.NET. 我正在使用VB.NET中的邮件应用程序。 The mail app sends mail in two steps :
邮件应用程序分两个步骤发送邮件:
1.It converts the Email body(rtf) to HTML 1.它将电子邮件正文(rtf)转换为HTML
2.Then it sends the converted HTML as the email body 2.然后将转换后的HTML作为电子邮件正文发送
For these, i am using EASendMail(to send email),Itenso RTF2HTML converter(to convert RTF to HTML) . 对于这些,我正在使用EASendMail(发送电子邮件),Itenso RTF2HTML转换器(将RTF转换为HTML) 。 Now my email body is basically a RichTextBox(bodytxt.text).The code used are :
现在我的电子邮件正文基本上是RichTextBox(bodytxt.text)。使用的代码是:
Imports Itenso.Rtf.Converter.Html
Imports EASendMail
Imports Itenso.Rtf.Support
Imports Itenso.Rtf
Dim rr As String = bodytxt.Rtf.Replace("\0", "")
Dim rtfDocument As IRtfDocument = RtfInterpreterTool.BuildDoc(rr)
Dim htmlConverter As New RtfHtmlConverter(rtfDocument)
Dim html1 As String = htmlConverter.Convert()
Dim oMail As New SmtpMail("TryIt")
Dim oSmtp As New EASendMail.SmtpClient()
oMail.From = fromtxt.Text
oMail.To = New AddressCollection(totxt.Text)
oMail.Subject = subjecttxt.Text
oMail.HtmlBody = html1
Dim oServer As New SmtpServer(MailConfig.host.Text)
oServer.Port = MailConfig.port.Text
oServer.ConnectType = SmtpConnectType.ConnectSSLAuto
oServer.User = fromtxt.Text
oServer.Password = MailConfig.password.Text
Dim r As Integer
If ListBox1.Items.Count <= 0 Then
Else
oMail.AddAttachment(ListBox1.Items(r))
End If
oSmtp.LogFileName = Application.StartupPath & "\maillog.OFPTX"
oSmtp.SendMail(oServer, oMail)
Now this code works fine and sends the email as HTML-maintaining all text formatting . 现在,此代码可以正常工作,并以HTML格式(保留所有文本格式)发送电子邮件。 The problem is, suppose i add an image in the rich textbox, then the image is sent but it can't be opened/viewed from my mail client's inbox.In Gmail, It shows as a broken image and "Open image in new tab" show "We can't display this image"...
问题是,假设我在富文本框中添加了一个图像,然后发送了该图像,但是无法从我的邮件客户端的收件箱中打开/查看该图像。在Gmail中,该图像显示为损坏的图像,而“在新标签页中打开图像”显示“我们无法显示此图像” ...
1.What am i doing wrong ?How to send the image not as an attachment but a part of the email body ? 1.我在做什么错?如何发送图像而不是附件而是电子邮件正文的一部分?
2.Can my code be improved ? 2.我的代码可以改进吗?
Ok so I've dealt with this issue many times. 好的,所以我已经处理了很多次了。 When you drag an image into the rich text box, it may just kind of "live there" in memory.
当您将图像拖到富文本框中时,它可能只是存在于内存中。
What is the markup look like in the rich text box? 富文本框中的标记外观如何? Typically there are 2 ways I've tackled this with web applications that involve rich text boxes (or any application) where you can drag an image in:
通常,我使用涉及富文本框(或任何应用程序)的Web应用程序来解决此问题的2种方法,您可以在其中拖动图像:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.