格式化HTML以通过system.net.mail发送吗? [英] Formatting HTML to send via system.net.mail?

查看:81
本文介绍了格式化HTML以通过system.net.mail发送吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好.

我已经在vb.net,.net 4框架中开发了一个小的smtp Windows应用程序.我已阅读以下文章如何通过VB.NET或C#从GMAIL帐户发送邮件. Windows编程,具有一些自定义功能 [ ^ ],并使用代码段来获取程序的主要功能.

我遇到的一个问题是,我一直在网上搜索很多地方而没有运气,是我在使用Richtextbox作为主要消息文本框(txtmessge),但是当我在HTML视图中发送消息时,它不保留格式设置属性,是否可以在richtextbox中以格式化的格式发送消息.

我认为这是代码中存在问题的地方:

<pre lang="vb"><br />
      Dim htmlview As String<br />
      Dim messagebyuser As String = txtmessage.Text<br />
      Dim locateS As String = "C:\logo.jpg"<br />
 htmlview = messagebyuser</pre><br />



还是我必须将消息构建为html结构?

任何帮助都会得到解决. =)

解决方案


如果富文本框包含html格式的字符串,则必须设置MailMessage的属性

IsBodyHtml为true.如果需要使用样式,请在heml文本中使用内联样式


也要注意,Outlook 2007以后的版本已更改了它读取HTML电子邮件的方式.

您将需要嵌入图像,而不是将其添加为HTML 标签.他们也改变了它读取StyleSheets的方式.

Microsoft在Outlook中中断了html电子邮件呈现 [ ^ ]

Hi Everyone.

i have been developed a small smtp Windows application in vb.net, .net 4 framework. ihave read the following article How to Send Mails from your GMAIL Account through VB.NET or C#. Windows Programming, with a Bit of Customization[^] and used snippets of codes to get the main funcationality of the program.

An issue i am stuck with and i have searched multple places on the net with no luck, is i am using a richtextbox for the main message text box (txtmessge) but when i send the message in HTML view, it doesnt retain the formatting properties, is it achievable to have a message sent as it formatted in the richtextbox.

i believe this is where the issue alies in the code:

<pre lang="vb"><br />
      Dim htmlview As String<br />
      Dim messagebyuser As String = txtmessage.Text<br />
      Dim locateS As String = "C:\logo.jpg"<br />
 htmlview = messagebyuser</pre><br />



or will i have to build the message into a html structure?

any help would be appericated. =)

解决方案

Hi
If the rich textbox contain strings in html format then you have to set the property of MailMessage

IsBodyHtml to true. If need to use styles, use inline style in the heml text


Also be aware that outlook 2007 onwards has changed the ways that it reads HTML emails.

you will need to embed images rather than add them as HTML tag. Also they have changed the way that it reads StyleSheets.

microsoft breaks html email rendering in outlook[^]


这篇关于格式化HTML以通过system.net.mail发送吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆