send email with ASP

Sending Email with ASP

All good websites need to be able to send and recieve email . Ok you could have a mailto link in your page pointing to your email address which when the user clicked on it their default email client opened up but why not let ASP handle this . We will use ASP and CDONTS for this task .

CDONTS is available on the Windows NT /2000 platforms and provides the necessary objects , methods and properties to send email . You can also send attachments , send HTML mail and various other tasks .

Lets Begin :

First of all we have to create an instance of the CDONTS object , we achieve this like this

<%
Dim objCdonts
Set objCdonts = Server.CreateObject("CDONTS.NewMail")
%>

Now we add the various importantemail addresses  to the script , these include the address you are sending to , the address where the mail is from .

objCdonts.To = "youraddress@youremail.com"
objCdonts.From = "myaddress@myemail.com"

Now lets add the subject line of the email message. We do this with the following.

objCdonts.Subject = "Hello this is my sample email"

OK hopefully you are still with me , an email is no use without some message in the actual body of it , here is how we go about this .

objCdonts.Body = "Hello , I am just testing this email script out "

OK that's our email all set up and ready to go but wait we need to send it and once it is sent it always good practice to delete the instance of the CDONTS object and free up resources on your server.

objCdonts.Send
Set objCdonts = Nothing

Lets see the complete script

<%
Dim objCdonts
Set objCdonts = Server.CreateObject("CDONTS.NewMail")
objCdonts.To = "youraddress@youremail.com"
objCdonts.From = "myaddress@myemail.com"
objCdonts.Subject = "Hello this is my sample email"
objCdonts.Body = "Hello , I am just testing this email script out "
objCdonts.Send
Set objCdonts = Nothing
%>