如何使用C#中的smtp将彩色内容作为电子邮件发送? [英] How to send Color content as a email using smtp in C#?

查看:88
本文介绍了如何使用C#中的smtp将彩色内容作为电子邮件发送?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hii,

i已使用smtp发送电子邮件,但在收件箱中签入时内容为纯文本(黑色内容)。



但我需要将彩色内容作为电子邮件从Windows表单应用程序发送。



i需要粘贴单词中的内容(彩色)并粘贴在

richtextbox的形式。

内容显示为彩色但邮件在检查时没有显示彩色内容。

请帮助我怎么做。

提前谢谢。

Hii,
i have sent email using smtp but the content is in the form of plain text(black colored content) when checked in inbox.

but i need to send the colored content as an email from windows form application.

i need to paste the content(colored) from the word and paste it in
richtextbox in form.
content is appearing as colored but the mail when checked it is not showing the colored content.
please help me how to do it.
Thanks in advance.

推荐答案

你可以使用内容类型text / html或text / rtf,用于整个邮件消息或其部分。使用HTML,您始终可以在HTML内容中嵌入一些CSS,并为元素和/或元素类定义所有颜色。 RTF的数据类型不太灵活,每个不同的文本片段都需要不同的样式;没有Office Word或HTML样式。



内容类型标题支持标准的媒体类型;其列表由IANA维护:

https:// www .iana.org / assignments / media-types / media-types.xhtml [ ^ ],

https://www.iana.org/assignments/media-types/media-types.xhtml#text [ ^ ]。



如果你想要要为整个邮件应用HTML内容类型,它可以像使用属性一样简单 IsBodyHtml

https://msdn.microsoft.com/en-us/library/system .net.mail.mailmessage.isbodyhtml(v = vs.110).aspx [ ^ ]。



对于零件和/或备用视图,请了解以下信息:

https://msdn.microsoft.com/en-us/library/system.net.mail.mailmessage.alternateviews%28v=vs.110%29 .aspx [ ^ ],

https://msdn.microsoft.com/en-us/library/system.net.mail.mailmessage.attachments%28v=vs.110%29 .aspx [ ^ ],

https://msdn.microsoft.com/en-us/library/system.net.mail.attachmentcollection%28v=vs.110%29 .aspx [ ^ ],

https://msdn.microsoft.com/en-us/library/system.net.mail.attachment%28v=vs.110%29.aspx [ ^ ]。



请注意,附件这个词有点误导,这可能会引起一些学生的困惑。没有什么是附加的,所有内容都作为部分嵌入到单个消息中。您可以通过属性 ContentDisposition 使附件表现

https://msdn.microsoft.com/en-us/library/system。 net.mail.attachment.contentdisposition(v = vs.110).aspx [ ^ ],





现在,剪贴板。您可以使用类 System.Windows.Forms.Clipboard System.Windows.Clipboard

https://msdn.microsoft .com / zh-cn / library / system.windows.forms.clipboard%28v = vs.110%29.aspx [ ^ ],

https://msdn.microsoft.com/en-us/library /system.windows.clipboard%28v=vs.110%29.aspx [ ^ ]。



你需要使用剪贴板数据格式 Html Rtf (四种不同类型,因为有两种不同的类型 DataFormats ,单独为F orms和WPF分开):

https://msdn.microsoft.com/en-us/library/system.windows.forms.dataformats%28v=vs.110%29.aspx [ ^ ] ,

https:/ /msdn.microsoft.com/en-us/library/system.windows.dataformats%28v=vs.110%29.aspx [ ^ ]。



如果您使用HTML,那么解析内容并按照您选择的方式将其映射到HTML上是您的工作。 RTF可以直接使用,但是你松开了所有的Word样式,只会保留每个不同文本片段的具体呈现。



-SA
You can do it, in particular, using the content type "text/html" or "text/rtf", for the whole mail message or its part. With HTML, you can always embed some CSS in your HTML content and define all your colors for elements and/or element classes. RTF is less flexible data type which requires different styles for each of the different fragment of text; there is nothing like Office Word or HTML styling.

Content-type header supports the standard media types; the list of them is maintained by IANA:
https://www.iana.org/assignments/media-types/media-types.xhtml[^],
https://www.iana.org/assignments/media-types/media-types.xhtml#text[^].

If you want to apply HTML content type for the whole message, it can be as simple as using the property IsBodyHtml:
https://msdn.microsoft.com/en-us/library/system.net.mail.mailmessage.isbodyhtml(v=vs.110).aspx[^].

For parts and/or alternate views, learn this:
https://msdn.microsoft.com/en-us/library/system.net.mail.mailmessage.alternateviews%28v=vs.110%29.aspx[^],
https://msdn.microsoft.com/en-us/library/system.net.mail.mailmessage.attachments%28v=vs.110%29.aspx[^],
https://msdn.microsoft.com/en-us/library/system.net.mail.attachmentcollection%28v=vs.110%29.aspx[^],
https://msdn.microsoft.com/en-us/library/system.net.mail.attachment%28v=vs.110%29.aspx[^].

Note that the term "attachment" is somewhat misleading, which cased confusion in some students. Nothing is really "attached", everything is embedded in a single message as parts. You can make such part behaving like attachment through the property ContentDisposition:
https://msdn.microsoft.com/en-us/library/system.net.mail.attachment.contentdisposition(v=vs.110).aspx[^],
.

Now, the clipboard. You can use the class System.Windows.Forms.Clipboard or System.Windows.Clipboard:
https://msdn.microsoft.com/en-us/library/system.windows.forms.clipboard%28v=vs.110%29.aspx[^],
https://msdn.microsoft.com/en-us/library/system.windows.clipboard%28v=vs.110%29.aspx[^].

You will need to use clipboard data format Html or Rtf (four different types, because there two different types DataFormats, separate for Forms and separate for WPF):
https://msdn.microsoft.com/en-us/library/system.windows.forms.dataformats%28v=vs.110%29.aspx[^],
https://msdn.microsoft.com/en-us/library/system.windows.dataformats%28v=vs.110%29.aspx[^].

If you use HTML, it's your job to parse content and map it on HTML the way you choose. RTF can be used directly, but you loose all the Word styles, will preserve only the concrete rendering of each different fragment of text.

—SA


这篇关于如何使用C#中的smtp将彩色内容作为电子邮件发送?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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