By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,854 Members | 856 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,854 IT Pros & Developers. It's quick & easy.

HTML Email Question

P: n/a
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

Mar 2 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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


Mar 3 '06 #2

P: n/a
Thank you Mark. I think this will work wonderfully. However, now I'm
considering making the HTML page an aspx page with data controls that
will look up the contact information from the DB. Therefore I don't
have to worry about the place holders. I think that would be best.
Then I can make that page serve multiple purposes.

Thanks again,
Tony

Mar 3 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.