0

I'm currently writing a web application that sends out various emails with dynamic textual content using the SmtpClient and MailMessage .net API classes - I just find I'm drowning in a sea of stringbuilders.

Are there any email/templateing frameworks to help with this sort of thing? That also work in medium trust.

Dan
  • 29,100
  • 43
  • 148
  • 207

5 Answers5

0

I'd use a template framework like NVelocity

EDIT: It seems like the SourceForge NVelocity is dead, but the guys of Castle Project had forked it. As I use Velocity for Java and NVelocity is the port for .NET I recommend it ;)

victor hugo
  • 35,514
  • 12
  • 68
  • 79
0

You could look at stringtemplate

NVelocity is what we used in my last project

Surya
  • 4,922
  • 8
  • 41
  • 54
0

Try T4 if you do not want to introduce another dependency to your project.

oscarkuo
  • 10,431
  • 6
  • 49
  • 62
  • T4 is a templating framework, which answers your question "Are there any email/templateing frameworks to help with this sort of thing?" – dss539 Jun 08 '09 at 19:07
0

I don't use a template framework, but I do use HTML pages as my email templates. I then put in variables like "<#UserName#>" into the HTML that get replaced in code. This allows me to easily edit the body of the email without having to touch the code.... Unless I want to add a few more new varibles. The other benefit to using standard HTML pages as my templates, is the ability for non-programmers to design/manage the email body layout...

Zachary
  • 6,522
  • 22
  • 34
0

In Some special cases when i can't use a tool and must write mine and as you said want to make loops through the template.

I create a normal aspx page in my project and put there all the controls i need "server controls, databinding controls"

And then call this page using a silent call:

HttpWebRequest request = (HttpWebRequest)WebRequest.Create("MyASPXPage.aspx");
request.Method = "GET";
response = request.GetResponse();
reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
result = reader.ReadToEnd();

after that you will have the result string variable contain all the page which you can send as a mail.

I used this once and it worked nice.

But sure if you found a tool to help you in that, this will be better.

Amr Elgarhy
  • 66,568
  • 69
  • 184
  • 301