///Sending HTML Email with ASP

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==

2010-05-26T11:00:58+00:00 June 1st, 2005|ASP|0 Comments

About the Author:

Amrit Hallan is a freelance web developer. You can checkout his website at http://www.bytesworth.com. For more such articles join BYTESWORTH REACHOUT at http://www.bytesworth.com/br/default.asp or if you have a web dev related question then post it at http://www.business180.com/index.php

Leave A Comment