Sending Email with CDONTS

Below is a script that will send an email using the NewMail Object provided that the server has the Collaboration Data Objects for Microsoft Windows NT Server (CDONTS) component installed on it.

Check with your webhost if you aren't sure whether CDONTS is installed. The SMTP service should be installed and running with Internet Information Services (IIS).

<%@ language= "VBscript" %>
<% Option Explicit
'declare your variables
Dim NewMail, Body
'create an instance of the NewMail Object
Set NewMail = Server.CreateObject("CDONTS.NewMail")
NewMail.To= "michael@codefixer.com" ' the email address it will be sent to
NewMail.From= "whoever@hotmail.com"   ' the email address it was sent from
Body= "Hi there, just testing codefixer's email tutorial out!"
NewMail.Subject = "Hello"
NewMail.Body = Body   
NewMail.Bodyformat=0  
NewMail.Mailformat=0
NewMail.Send
Set NewMail=Nothing
%>

If you would like to send it as plain text rather than HTML just remove the 2 lines
NewMail.Bodyformat=0
NewMail.Mailformat=0

Important - CDONTS is deprecated on Windows XP, Windows 2003 and only included on Windows 2000 for backward compatability. Learn how to send email with the CDOSYS component.

Just save your file as email.asp and run it on the server and it should work. Have a look at the form to email tutorial which will make a more dynamic page.

Advertisements



MembersPro

MembersPro PayPal - ASP Membership software

Plug and play ASP membership script that integrates with PayPal to let you charge recurring membership fees.

Get your best asp web hosting provider now and save 25%