How to Send Both Text & HTML Email in Classic ASP
Active Server Pages or ASP is a server side Web-scripting language created by Microsoft that gives website owners the ability to add programming functionality to webpages. ASP can be used to capture, manipulate and store data as well as send email messages. One of the built-in components is CDOSYS. This object is designed to make it easy to write scripts that format and send email messages from your webpage.
Instructions
-
-
1
Create a webpage and save it with the suffix .asp. This tells the server that the page is an active server page so your code will be processed.
-
2
Add the ASP script opening and closing tags to your page. These tags tell the server that the contents of the tags are ASP script code.
<% 'This is the script opening tag
%> 'This is the script closing tagNote: ' Denotes a comment. Comments are used to explain the code but are ignored by the server.
-
-
3
Create a CDOSYS object instance.
Set myMessage=CreateObject("CDO.Message")
-
4
Set the email message subject line, the "from" email address and the "to" email address.
myMessage.Subject="This is the email subject line"
myMessage.From="from@domain.com"
myMessage.To="to@domain.com" -
5
Set the text or HTML of the email message.
myMessage.TextBody="This is the body of a text email message."
Or
myMessage.HTMLBody = "<h1>This is the body of an HTML email message.</h1>"
-
6
Send your email message and destroy the CDOSYS object instance.
myMessage.Send
set myMessage=nothing -
7
Review your completed script.
<%
Set myMessage=CreateObject("CDO.Message")
myMessage.Subject="This is the email subject line"
myMessage.From="from@domain.com"
myMessage.To="to@domain.com"
myMessage.TextBody="This is the body of a text email message."
myMessage.Send
set myMessage=nothing
%>
-
1
References
- Photo Credit email image by Hao Wang from Fotolia.com