tags:

views:

175

answers:

5

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.

A: 

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
last version 2003? Still up to scratch?
Dan
Here the answer, hehe - http://stackoverflow.com/questions/699094/is-the-nvelocity-project-dead-are-there-alternatives
victor hugo
A: 

You could look at stringtemplate

NVelocity is what we used in my last project

Surya
A: 

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

oykuo
T4's done seem fit for this purpose
Dan
T4 is a templating framework, which answers your question "Are there any email/templateing frameworks to help with this sort of thing?"
dss539
A: 

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
What if he wants to include a loop in his 'template'?
victor hugo
A: 

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