Thursday, January 24, 2008

Send an Email using ASP CDONTS

Sending an Email in ASP is pretty straight forward. The code is below:

Set objEmail = Server.CreateObject("CDONTS.NewMail")
objEmail.to = "to_email@gmail.com"
objEmail.From = "your_email@domainname.com"
objEmail.Subject = "Subject"
objEmail.Body = "Email Body"
objEmail.send
Set objEmail = nothing

There you go thats how you send an email. Now lets break it down!

This creates a NewMail object from the CDONTS library.
Code:
Set objEmail = Server.CreateObject("CDONTS.NewMail")
To Property
The To property lets you specify who the email is to, rather self explanatory! The property has the following form
Code:
objEmail.to = "to_email@gmail.com"
From Property
The From property lets you, guess it, specify who the email is from. and it looks like this;
Code:
objEmail.From = "your_email@domainname.com"
Subject Property
This is getting rather repitive don't you think? The subject property lets you define the subject and looks, and you may have already guessed, like this;
Code:
objMail.Subject = "Subject"
Body Property
Now to the body section. This sets the text of the message, or HTML, which we'll look at soon. And it looks like this;
Code:
objMail.Body = "Email Body"
Almost done we send the email using the Send method.
Code:
objEmail.send
And then we release the resource of the object
Code:
Set objEmail = nothing

Thats it to send an email. If you need any other help please post your comments below

AddThis Social Bookmark Button

1 comment:

nikhil said...

i have tried this code but it is not working...Is there any other method to send mail through asp