Question

I have a application that generates a couple of different mails. These mails are currently build up using a string builder that generates a HTML based string that is the mail content.

This approach is getting messy. The code is objects mixed with HTML, etc, etc. What I'd like is to have a template similar to the one used in for example MVC and then use the output of this template to add to the mail.

Can this be done using for example T4 add how wound that work or should I use another approach for this?

The templates don't have to be editable at runtime even if that would be nice.

Was it helpful?

Solution

It can be done with T4. It would work exactly the way it does in MVC.

You should consider getting the Clarius T4 Editor, as Visual Studio does not come with intellisense for T4 out of the box, and the Clarius T4 editor can provide that.

OTHER TIPS

Have you considered just using XSLT? You can easily create HTML documents from raw XML by applying an XSL Transform in .Net

We store XSL templates in the database, and use a simple NAME/VALUE pair approach to populate the templates in code. It is very effective and flexible, and the output can be piped to the browser easily. Alternatively you could just store the individual templates in files on the server and load them up that way.

Either way, the amount of code to implement this is relatively simple, and .Net has many classes in place to facilitate this. If you want an example of how we implemented this, leave a comment and I will append some code examples to this answer.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top