Connecting Tech Pros Worldwide Forums | Help | Site Map

HTML Email Question

akylitis
Guest
 
Posts: n/a
#1: Mar 2 '06
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


Mark Harris
Guest
 
Posts: n/a
#2: Mar 3 '06

re: HTML Email Question


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 <tonyk@reactornet.com> wrote:
[color=blue]
> 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
>[/color]

akylitis
Guest
 
Posts: n/a
#3: Mar 3 '06

re: HTML Email Question


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

Closed Thread