CDONTS !! Dynamic Data in email

D

dave

I am trying to generate an email from the webpage using code below, which
works fine. However I want to be able to include some dyanmic data how do I
go about it ?can anybody point me in the direction of some sample code ?

Thanks Dave


<%@ Language=VBScript %>
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<%

Dim myMail
Dim HTML
Set myMail = CreateObject("CDONTS.NewMail")

HTML = "<!DOCTYPE HTML PUBLIC""-//IETF//DTD HTML//EN"">"
HTML = HTML & "<html>"
HTML = HTML & "<head>"
HTML = HTML & "<meta http-equiv=""Content-Type"""
HTML = HTML & "content=""text/html; charset=iso-8859-1"">"
HTML = HTML & "<meta name=""GENERATOR"""
HTML = HTML & " content=""Microsoft Visual Studio 6.0"">"
HTML = HTML & "<title>HTMLMail</title>"
HTML = HTML & "</head>"
HTML = HTML & "<body bgcolor=""FFFFFF"">"
HTML = HTML & "<IMG SRC=""http://www.microsoft.com/library/"
HTML = HTML & "images/gifs/homepage/microsoft.gif"" BORDER=0 "
HTML = HTML & "WIDTH=167 HEIGHT=36 ALT=""Microsoft Corporation"">"
HTML = HTML & "<p><font size =""3"" face=""Arial""><strong>"
HTML = HTML & "Microsoft Exchange CDONTS Example</strong></p>"
HTML = HTML & "<p><font size =""2"" face=""Tahoma"">"
HTML = HTML & "CDO for NTS allows an easy way to send mail.<br>"
HTML = HTML & "This example shows how the content can be "
HTML = HTML & "an HTML page<br>"
HTML = HTML & "which allows you to send rich text and"
HTML = HTML & "inline graphics.</p>"
HTML = HTML & "</body>"
HTML = HTML & "</html>"

myMail.From="(e-mail address removed)"
myMail.To="(e-mail address removed)"
myMail.Subject="Sample CDONTS HTML Message"
myMail.BodyFormat=0
myMail.MailFormat=0
myMail.Body=HTML
myMail.Send
set mymail=nothing
Response.Write "Message Sent"
%>
</HEAD>
<BODY>
</BODY>
</HTML>
 
R

Ray Costanzo [MVP]

dave said:
I am trying to generate an email from the webpage using code below, which
works fine. However I want to be able to include some dyanmic data how do I
go about it ?can anybody point me in the direction of some sample code ?

Dynamic how?

Ray at home
 
D

Dave

Ray Costanzo said:
do

Dynamic how?

Ray at home
Dyanmic in the sense of I want to be able to pull data from sql and display
it in a formatted html table which in turn is embeded in an email message,
basically like when you buy something online and you have a confirmation
email showing what you ordered, that is what I want to be able to do. I may
be going completly the wrong way about it due to my ignorance any help is
gratefully received

Dave
 
R

Ray Costanzo [MVP]

Do you know how to build a web-page that would display this data? If so,
it's the same basic idea, except that instead of writing the html to a
browser, you save it to a variable that will become the .HTMLBody of your
CDO.Message object (assuming that's what you use).

So, forget the e-mailing for a moment, and focus on just creating a web page
with the data you want. Can you do that?

Ray at work
 
D

Dave

Thanks Ray,

I can build an asp page that shows the data I require to be sent in the
email , Just about ! :)

What do I do next ?

Dave
 
R

Ray Costanzo [MVP]

Well, let's say that this is your page that returns data:

page.asp:
<html><head><title>something</title></head>
<body>
<%
UserID = 6
Dim oADO, oRS
Set oADO = CreateObject("ADODB.Connection")
Set oRS = oADO.Execute("SELECT COUNT(transID) FROM Trans WHERE UserID=" &
UserID)
%>
You have placed <%=oRS.Fields.Item(0).Value%> orders.
<%
oRS.Close : Set oRS = Nothing
oADO.Close : Set oADO = Nothing
</body>
</html>



To turn that into an e-mail, you'd dump all the html to a variable, i.e.

<%
sBody = "<html><head><title>something</title></head>" & vbCrLf
sBody = sBody & "<body>" & vbCrLf
UserID = 6
Dim oADO, oRS
Set oADO = CreateObject("ADODB.Connection")
Set oRS = oADO.Execute("SELECT COUNT(transID) FROM Trans WHERE UserID=" &
UserID)
sBody = sBody & "You have placed " & oRS.Fields.Item(0).Value & " orders." &
vbCrLf
oRS.Close : Set oRS = Nothing
oADO.Close : Set oADO = Nothing
sBody = sBody & "</body>" & vbCrLf
sBody = sBody & "</html>"

Set oCDO = CreateObject("CDO.Message")
oCDO.From = "(e-mail address removed)"
oCDO.To = "(e-mail address removed)"
oCDO.Subject = "orders"
oCDO.HtmlBody = sBody
oCDO.Send
%>

Does that make sense?

Ray at work
 
D

dave

brilliant thankyou


Ray Costanzo said:
Well, let's say that this is your page that returns data:

page.asp:
<html><head><title>something</title></head>
<body>
<%
UserID = 6
Dim oADO, oRS
Set oADO = CreateObject("ADODB.Connection")
Set oRS = oADO.Execute("SELECT COUNT(transID) FROM Trans WHERE UserID=" &
UserID)
%>
You have placed <%=oRS.Fields.Item(0).Value%> orders.
<%
oRS.Close : Set oRS = Nothing
oADO.Close : Set oADO = Nothing
</body>
</html>



To turn that into an e-mail, you'd dump all the html to a variable, i.e.

<%
sBody = "<html><head><title>something</title></head>" & vbCrLf
sBody = sBody & "<body>" & vbCrLf
UserID = 6
Dim oADO, oRS
Set oADO = CreateObject("ADODB.Connection")
Set oRS = oADO.Execute("SELECT COUNT(transID) FROM Trans WHERE UserID=" &
UserID)
sBody = sBody & "You have placed " & oRS.Fields.Item(0).Value & " orders."
& vbCrLf
oRS.Close : Set oRS = Nothing
oADO.Close : Set oADO = Nothing
sBody = sBody & "</body>" & vbCrLf
sBody = sBody & "</html>"

Set oCDO = CreateObject("CDO.Message")
oCDO.From = "(e-mail address removed)"
oCDO.To = "(e-mail address removed)"
oCDO.Subject = "orders"
oCDO.HtmlBody = sBody
oCDO.Send
%>

Does that make sense?

Ray at work
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,708
Latest member
SherleneF1

Latest Threads

Top