如何从 C# 应用程序创建 HTML 文本?
我有 C# 应用程序,必须将一些信息存储到 MS SQL 中 稍后将通过 DB Mail 发送到电子邮件。
在 C# 应用程序中,我有一个具有多个属性的类,我需要使用它来生成电子邮件文本。所以我想要的是设置一个带有变量占位符的模板。我需要将文本创建为 HTML 和纯文本。
您需要什么工具、库 推荐 HTML 吗?
String.Format() 是最好的替代方法吗 使用纯文本?
I have C# application that must store some information into MS SQL that
would be later sent to email with DB Mail.
Within C# application I have a class with several properties and I need to use it to generate email text. So what I would like is set up a template with placeholders for variables. I need to create text as HTML and plain text.
What tools, libraries would you
recommend for HTML?Is String.Format() best alternative to
work with plain text?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在其他应用程序中,我通过在某处提供电子邮件正文(SharePoint 列表、数据表)来实现此目的,该正文已采用正确的格式,但带有与应用程序中的信息相对应的命名占位符。
然后发送电子邮件意味着用正确的信息替换占位符。 StringBuilder.Replace 工作正常。
I do this in other applications by having the e-mail body available somewhere (SharePoint list, data table) already in the right format, but with named placeholders, corresponding to the information you have in your application.
Then sending the e-mail means replacing the placeholder with the right information. StringBuilder.Replace works fine.
我想说,您需要决定的最重要的事情是何时对文本进行编码。如果您通过电子邮件发送用户提供的文本,则需要先对其进行 HtmlEncode,然后再将其包含在电子邮件中。只要每个消费者在使用它之前对其进行编码,就可以将其“按收到的状态”存储在数据库中。我通常在从数据库“获取”数据的数据层中执行此操作。
I would say the most important thing you need to decide is when to encode the text. If you are emailing text supplied byusers, you will want to HtmlEncode it before including it in an email. It's probably ok to store it "as recieved" in the data base as long as every consumer encodes it before using it. I typically do this in the data layer that "gets" data from the data base.