View Full Version : composing HTML email
Moeis
07-31-2003, 01:41 PM
Hiya
you know when you send HTML using ASP, you have to do all this:
sHTML=sHTML & "<html><head>"
sHTML=sHTML & "<title>title</title>"
sHTML=sHTML & "</head><body>...blah...blah..blah"
....
this can get really annoying to compose. Isn't there an easier way, preferably to point ASP at a HTML file and have it use all the HTML in the file for the email. And if that's possible, yipee! :-) is it also possible to get ASP to parse ASP within that file, such as:
<html><head>
<title><%=sTitle %></title>
</head><body>...blah...blah..blah
Many thanking yous,
m03;5
glenngv
07-31-2003, 02:22 PM
put it in a function and in an include file
Function createHTML(ByVal strTitle, ByVal strContent)
dim sHTML
sHTML=sHTML & "<html><head>"
sHTML=sHTML & "<title>" & strTitle & "</title>"
sHTML=sHTML & "</head><body>"
sHTML=sHTML & strContent
sHTML=sHTML & "</body></html>"
createHTML = sHTML
End Function
then you can call it like:
msgBody = createHTML("Reply","This is an auto-generated email. blah blah blah.")
Moeis
07-31-2003, 04:25 PM
Thanks glenngv,
...but I was trying to avoid the business of:
sHTML=sHTML & "<html><head>"
sHTML=sHTML & "<title>" & strTitle & "</title>"
sHTML=sHTML & "</head><body>"
sHTML=sHTML & strContent
sHTML=sHTML & "</body></html>"
...and get something like:
sHTML=PageToEmail("OrderForm.html")
... or even:
sHTML=Eval("OrderForm.asp")
glenngv
07-31-2003, 05:42 PM
you can do
sHTML=PageToEmail("OrderForm.html")
by reading the content of the specified page using FileSystemObject or XMLHTTP but that would be an overkill.
oracleguy
07-31-2003, 05:50 PM
Here is an example using FSO.
<%
Function ReturnHTML(strFileName)
Dim fs, f, strContents
Set fs=Server.CreateObject("Scripting.FileSystemObject")
Set f=fs.OpenTextFile(strFileName, 1)
do while f.AtEndOfStream = false
strContents=strContents & f.ReadLine
loop
f.Close
Set f=Nothing
Set fs=Nothing
ReturnHTML=strContents
End Function
%>
Then you'd just call it like:
objCDO.Body=ReturnHTML(Server.MapPath("orderform.htm"))
Moeis
07-31-2003, 08:36 PM
Thanks glenngv, Thanks Oracleguy!
That function is just what I was looking for, Oracleguy, cheers!
What I might do is create the file first, using ASP to dynamically add rows to tables, etc. And then read the whole file back.
thnx +++
m03;5
whammy
08-07-2003, 01:33 AM
FSO is extremely useful in conjunction with ASP... if you haven't mastered it yet, I'd go here and go through EVERYTHING - just so you know what's possible:
http://www.w3schools.com/asp/asp_ref_filesystem.asp
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.