views:

224

answers:

2

So I'm writing this EXE to process refunds, and when the job's done, we're sending out an email to a list of users that will probably be like:

DO NOT REPLY

Refund processing has completed. N refunds were successfully processed. We encountered N errors. Please check http://whatever.url for a detailed report.

Thanks,

A computer

DO NOT REPLY

So, we're not talking about grinding out hundreds of emails here, just one a day with the relevant info slipstreamed in. It's unlikely that this email will ever be modified, and never by non-technical staff. How should I go about storing this and processing the template into the email? C# String.Format style with {0} and {1}, etc? XML/XSLT (seems like a hassle)? Do I store the template in App.config or put it in the database or something different altogether?

What did I ever do before StackOverflow? :)

+4  A: 

I would take the easy way out. I assume you want to send a HTML mail message here.

I suggest you create a HTML file with how you want the mail to look. Replace all names/variables with things like #COMPANYNAME#. save the file and rightclick on your Project in Visual Studio. Go to Properties then Resources. Now drag the HTML file into the resources and give it a decent name (here: MyMailTemplate).

Now from your code you can refer to it from Properties.Resources.MyMailTemplate. You can use it as a string. Replace the #PARAMETER# text with the actual values.

Done and easy to edit!

Zyphrax
taking this one, it seems easiest. Thanks!
Chris McCall
Just came back to heap extra praise on this answer. I'm already done with the entirety of the email portion of my app! Thanks again!
Chris McCall
Good to hear! Thnx!
Zyphrax
A: 

I usually store the template in a text file with custom placeholder markup, although you could use the c# String.Format style for the placeholders. I reference the filename in the app.config, I can then load the text template in, replace the markup and send the email.

This keeps everything pretty simple and it's possible to update the email text without any recompiling.

Steve Temple