Web Development

Sending HTML Email with ASP

Sending HTML Email with ASP

Last time you learnt how to receive or send form data using ASP. Let’s now see how we can send HTML messages using the Active Server Pages. The process is quite similar to sending the regular, text message, but yes, there are a few modifications. Using the code given below, you can send HTML messages:

== Code Begins ==

<%

Dim htmlMess ‘ THIS STORES THE HTML CODE
‘ PLEASE TAKE CARE ABOUT YOUR DOUBLE QUOTES

htmlMess = "<html><head><title>HTML message in Email</title>"

htmlMess = htmlMess & "<style>"

htmlMess = htmlMess & "h1{font-family : Arial; font-size : 16pt; font-weight : bold; color: #000000;}"

htmlMess = htmlMess & "p{font-family : Arial; font-size : 10pt; color: black; text-align : justify;}</style></head>"

htmlMess = htmlMess & "<body bgcolor=’#ffffff’>"

htmlMess = htmlMess & "<h1>My HTML Message from an ASP Page!</h>"

htmlMess = htmlMess = & "<p>This message has been written in HTML format.</p></body></html>"

‘ FIRST I’LL SHOW HOW TO DO IT IN CDONTS, AND THEN IN SMTP

Dim oSendMailer

‘ CDONTS BEGINS

Set oSendMailer = Server.CreateObject("CDONTS.NewMail")

oSendMailer.To = "ToEmail"
oSendMailer.From = "FromEmail"
oSendMailer.Subject = "Subject Matter"

‘ THE FOLLOWING ARE THE EXTRA SETTINGS:
oSendMailer.BodyFormat = 0
oSendMailer.MailFormat = 0

oSendMailer.Body=htmlMess

oSendMailer.Send

set oSendMailer = nothing

‘ CDONTS ENDS

‘ SMTP BEGINS

Set oSendMailer = Server.CreateObject("SMTPsvg.Mailer")

oSendMailer.FromAddress = "FromAddress"

oSendMailer.FromName = "FromName"

oSendMailer.AddRecipient "Recipient Name", "RecipientEmail"

oSendMailer.RemoteHost = "mail.yourdomain.com"

oSendMailer.Subject = "Subject Matter"

oSendMailer.ContentType="Text/HTML"

oSendMailer.BodyText = htmlMess

oSendMailer.SendMail

set oSendMailer = nothing

‘ SMTP ENDS

%>

== Code Ends==

About the author

Written by Amrit Hallan.

Amrit Hallan is a freelance web developer. You can follow the link below to checkout his website.

If you found this post useful you may also want to check these out:

  1. Sending Cookies By Email
  2. Emailing Form Data with ASP
  3. How To Send Email With Perl, Part I
  4. How To Send Email With Perl, Part III
  5. HTML Tables
  6. How To Send Email With Perl, Part II