473,401 Members | 2,127 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,401 software developers and data experts.

HTML Email Question

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
2 1404
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Nancy | last post by:
Hi, Guys, I am new to Python. I am trying to following the example on http://www.modpython.org/live/current/doc-html/tut-pub.html In this example, it gives the following html code, <form...
9
by: quikquic | last post by:
Suppose I download a html file with javascript in it, for example, <html> <body> <script language="JavaScript"> document.write("Hello"); </script> </body> </html>
8
by: Chris Sharman | last post by:
See the bottom of http://www.prestonbridge.pwp.blueyonder.co.uk/index2.htm (4th line of the club officers section). The mark-up's validated html 4 & css, but in ie5.0/Win2000 my surname...
4
by: Francois Keyeux | last post by:
hello everyone: i have a web site built using vbasic active server scripting running on iis (it works on either iis 50 and 60, but is designed for iis 50) i know how to create a plain text...
11
by: VB Programmer | last post by:
Is there a limit as to how big an aspx page's html can be? (number of characters) Why do I ask? I have a webform with a lot of ActiveX controls (shows up as OBJECT in html). When I place like...
4
by: clintonG | last post by:
Technically speaking, this issue is not about modifying the HTML generated by server controls but preceding the HTML generated by server controls with an HTML control generated on the basis of the...
6
by: Paolo Pignatelli | last post by:
I have an aspx code behind page that goes something like this in the HTML view: <asp:HyperLink id=HyperLink1 runat="server" NavigateUrl='<%#"mailto:" &amp;...
11
by: Nathan Sokalski | last post by:
I add several JavaScript events (onchange, onkeypress, etc.) to Controls using the Add method of the Attributes collection. However, if the JavaScript code contains certain characters, such as & or...
2
by: Giedrius | last post by:
hi, i have an idea to make admin tool on home computer, that would generate html files using some kind of templates and database data and put these generated html files to public web server, witch...
21
by: maya | last post by:
hi, I'm designing an HTML email for a client.. I know general guidelines (no CSS, no JavaScript... although I do use limited CSS, inside tags (as in <span style=".."we do this at work and it...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.