Sending HTML Mail with ASP

Sending HTML Mail with ASP
HTML mail is in essence a mail message that has HTML commands in it, instead of just text. It allows the mail message to show images, provide links, and look pretty.

It can get complicated to send a well formatted HTML message. So start with the basics. Read up on Sending a Mail Message with ASP and make SURE you can successfully send messages in regular text. You only want to have to troubleshoot one problem at a time!

OK, so your mail is going out properly. Now you want to send a message with say BOLD LETTERS in it. Again, start small so if you hit a problem you can easily figure out what it is.

Just like before, start out by setting up the to-email, the from-email, and the subject line:

FromEmail = ""
ToEmail = ""
Subject = "Here is your order confirmation"

next, set up your actual email message. Now that it will be a HTML message, remember to use the P and/or BR commands to separate your paragraps.

EmailMessage = "Thank you for order!<BR>" & CHR(13) & _
"Here are the details of your order.<BR>" & CHR(13) & _
"<B>This Detail Is In Bold</B><BR>" & CHR(13) & _
"...details...<BR>" & CHR(13)

Note that the CHR(13)s just put hard returns after the lines, but in HTML hard returns are ignored.

OK you have your message, with line breaks and a bold part. Now you have to tell the mailer that you want this to be sent as a HTML message and not just as a text message. Otherwise the end user will see lots of HTML commands instead of seeing a pretty message.

Dim objMail
set objMail = CreateObject("CDONTS.NewMail")
Impt = 1
objMail.MailFormat = 0
objMail.BodyFormat = 0

The MailFormat and BodyFormat are what indicate this is a HTML message. Finally, like all good HTML, the HTML has to start and end with a HTML and BODY tag. So adjust your email message to have the proper wrapper.

FinalMessage = "<HTML><BODY> " & _
EmailMessage & "</BODY></HTML>"

Now send the message and close the connection

objMail.Send FromEmail,ToEmail,Subject,FinalMessage,Impt
set objMail = Nothing

There you go! Once you get a basic HTML message going out, you can enhance it with colors, graphics, and much more - just about anything you can do in HTML.

Sending a Mail Message with ASP

Introduction to ASP Ebook

Download this ebook to get everything you need to know about learning ASP - from a step by step tutorial to function lists, sample code, common errors and solutions, and much more! 101 pages.

Related Articles
Editor's Picks Articles
Top Ten Articles
Previous Features
Site Map

Content copyright © 2023 by Lisa Shea. All rights reserved.
This content was written by Lisa Shea. If you wish to use this content in any manner, you need written permission. Contact Lisa Shea for details.