views:

177

answers:

2

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.

  1. What tools, libraries would you recommend for HTML?

  2. Is String.Format() best alternative to work with plain text?

+4  A: 

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.

Timores
What is the benefit of storing "Format String" in data table instead of directly in C# program? If you modify placeholders you'll have to modify C# as well. Am I wrong?
Captain Comic
Say your data includes 'first name', 'last name', etc. In an external storage, you have an e-mail template with "hello %FirstName%, how is life today?". At run-time, you replace %FirstName% by the 'first name' attribute and you send the resulting text.The user should have a way to modify the templates without asking you to modify the app.Of course, adding a new placeholder (e.g. 'middle name') requires a change of the application.
Timores
+1  A: 

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.

No Refunds No Returns