14
How easy is it to send emails using HTML template
2 Comments · Posted by Administrator in Classic ASP, IT
Most of the time we send emails through our websites, at least one of our web page have that functionality. And most of the time we send simple text and sometimes we make it bit complex by adding html codes to send HTML emails to make it more attractive.
Here I have a quick script which will help you to send email using external HTML Template, no need to write html code in your asp page.
First create any html template page and save it in your server (let’s say we create temp.html under email folder /email/temp.html)
Now in our classic asp page, after we are happy with all criteria/mandatory fields being filled from the form, we just need to do is -
<%
Dim myF
set myF = server.CreateObject("Scripting.FileSystemObject")
Fname = Server.MapPath("\") & "\email\temp.html"
Set CurF = myF.OpenTextFile(Fname)
ContentOfFile = CurF.readAll
Set JMail = Server.CreateObject("JMail.Message")
JMail.Logging = False
JMail.From = "noreply@yourwebsite.com"
JMail.AddRecipient "visitor@yourwebsite.com"
JMail.AddHeader "X-Originating-IP", Request.ServerVariables("REMOTE_ADDR")
JMail.AddHeader "X-Originating-URL", Request.ServerVariables("URL")
JMail.Priority = 2
JMail.Subject = "Thank you for your interest"
JMail.ContentType = "text/html"
JMail.Body = ContentOfFile
JMail.Send ("localhost")
JMail.Close
set JMail = nothing
%>
And that’s done, your visitor will get nice HTML email. Here I am using JMail component to send email on Classic ASP. It does not matter whichever component you want to use, all works almost in same fashion.
classic asp · Email · html · jmail · template

teo · October 22, 2011 at 3:08 am
you forgot to explain about passing variables to the html file like tokens eg. hello #FirstName# that is the interesting part .
teo · October 22, 2011 at 3:11 am
maybe your readers should check this post : http://www.evagoras.com/2011/02/07/formatting-complex-asp-output-using-html-templates/