Sending HTML Email with ASP

by Amrit Hallan
Byteswoth.com
Thursday, 18th August 2005
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==


Options:
Printer Friendly
Email Friend

About The Author:

Amrit Hallan is a freelance web designer. For all web site development and web promotion needs, you can get in touch with him at amrit@bytesworth.com . For further details, visit http://www.bytesworth.com You can subscribe to his newsletter [BYTESWORTH REACHOUT] on Web Designing Tips & Tricks by sending a blank email at bytesworth-subscribe@topica.com.

Developer Categories



Developer Tutorials
ASP
CGI & Perl
CSS
Flash
HTML
Java
JavaScript
MySQL
PHP
Python
XML

Developer Documentation

Developer Tools



Search our Developer Tutorials
  The DevSyndicate Network