.NETGURU
Dyanamic HTML out of a Database
Messages   Related Types
This message was discovered on ASPFriends.com 'aspngdata' list.


Bryan Andrews
We have a subscription service that reads html stored in a table for =
things (email content) such as Welcome Messages, Opt Out, Passwords, =
etc., and I need to be able to dynamically insert things such as the =
users email address etc. when I send it.

I have already gone down the path of just putting made up fields in the =
html like: [[usersemail]] and doing a replace on it when I am formatting =
the email.

While this works ok, I feel like there may be an easier (and perhaps =
more logical) way to do this.=20

Maybe not though.

Thanks for any thoughts...

Reply to this message...
 
    
Michael Storey
If all you are doing is creating HTML to be inserted into an email why =
not create a page that contains bound fields. This page can then be =
requested in memory and the HTML can be read out of it. I do a similar =
thing using the (cut down) code below. The EmailToSend.aspx is a page =
containing the dynamic information to be sent to the indidvidual user. I =
loop through this code using a datareader object (dr here). BTW this =
code can be put anywhere it doesn't necessarily have to be in the code =
behind of an aspx page.

The performence of this is actually suprisingly good. I tested it on =
about 10000 records and it took about a dozen or so seconds. I would =
imagine millions of records (SPAM!) would cause problems though.

''''''' Imports may not need some of these=20
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.IO
Imports System.Net
Imports System.Web.Mail

Dim objResponse As WebResponse
Dim objRequest As WebRequest =3D =
System.Net.HttpWebRequest.Create("EmailToSend.aspx?UserID=3D" + =
CStr(dr.Item("User_ID")))

objResponse =3D objRequest.GetResponse
Dim sr As New StreamReader(objResponse.GetResponseStream)
Dim strTheMessage As String =3D sr.ReadToEnd()

Dim msgMail As New MailMessage()
msgMail.To =3D dr("email_address")
msgMail.From =3D "Michael"
msgMail.Subject =3D "DO NOT reply to this message"
msgMail.BodyFormat =3D MailFormat.Html
msgMail.Body =3D strTheMessage

Try
SmtpMail.SmtpServer =3D "whatever"
SmtpMail.Send(msgMail)
Catch e As Exception
Response.Write(SmtpMail.SmtpServer + e.Message)
End Try

Reply to this message...
 
 
System.IO.StreamReader
System.Net.HttpWebRequest
System.Net.WebRequest
System.Net.WebResponse
System.Web.Mail.MailFormat
System.Web.Mail.MailMessage
System.Web.Mail.SmtpMail




ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
Ad


Need Dot Net Interview Questions?
Ask ExamGuru, Inc. for advice and help on Passing .Net Interviews
.Net Projects
Best-of-breed application framework for .NET projects, developed by ExamGuru, Inc. and ExamGuru IT
Free .net Help
Commission ExamGuru, Inc. and his team for your next bespoke software project
FogBUGZ
The only bug tracking system carefully crafted with one goal in mind: helping teams create great software.
Awesome Tools
If you don't know about these, you're missing out... IT Certification Questions
IT Interview Questions
Free Oracle 10g Training
MCSE Boortcamp
Cisco Study Guides
Cheap Study Guides
Exact Questions
Dot Net Interview Questions
Oracle OCP
Cheap Travel
Designer Perfumes - Wholesale Prices
Free Programming Tutorials
 
ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
 Copyright © ExamGuru, Inc. 2001-2006
Contact Us - Terms of Use - Privacy Policy - www.dot-net-guru.com - www.examguru.net - www.oraclesource.net - www.itinterviews.net - www.examguru.net/ITCertification