Tony,
You could store the HTML file on the server as say "emailtemplate.html"
and put some unique code where you want to replace sections with the form
variables, eg:
[--------------------------------------------------------------------------------------]
<html>
<body>
<strong>First Name: </strong> {!FIRSTNAME!}<br />
<strong>Surname: </strong> {!SURNAME!}<br />
<strong>Comments: </strong> {!COMMENTS!}<br />
</body>
</html>
[--------------------------------------------------------------------------------------]
Then:
[--------------------------------------------------------------------------------------]
// need to add using System.IO;
// open the file
StreamReader sr = new StreamReader("emailtemplate.html");
string template = sr.ReadToEnd();
sr.Close();
// replace the template fields
template.Replace("{!FIRSTNAME!}", _firstName);
template.Replace("{!SURNAME!}", _surname);
template.Replace("{!COMMENTS!}", _comments);
// set mail.body to template.
[--------------------------------------------------------------------------------------]
On Fri, 03 Mar 2006 06:59:23 +0800, akylitis <to***@reactornet.com> wrote:
Hello:
Anyone have an opinion on the best way to formulate a dynamic HTML
email? Thus far I have figured out that the only way to "build" the
HTML prior to the email (I'm using System.Net.Mail) is to manually
build the HTML string in code or "screen scrape" a stream from a
WebRequest.
I've tried both ways and I'm torn. I hate building HTML through
strings; I'd rather create and manage an HTML file. However, the final
HTML needs to be dynamic enough to display data collected from a
"Contact Us" form. At the point of the email, the data is already
posted to the DB but I'm not sure if I want to hit the DB again if the
data is already part of the business object I already have created.
I think what I'm really looking for is a way to use an html template
somehow and "place" the data in the template, set the value to the
mail.body and be done. Any thoughts?
Tony