Sending an email with CDONTS
There are times in ASP when you would like to send emails.... scary!! Without jumping through hoops, I will endeavour to explain one of the many methods of doing so.
As most of you know, ASP is a technology resident on Windows NT Servers (It is possible to run ASP under Linux, Unix but we wont go into that here). With ASP running on a Windows box, we have access to something called 'Collaborative Data Objects for NT Server'.
For reasons of keeping things simple, this is always referred to as CDONTS. This object is one of many used for sending emails from ASP, but is the only object we have access to by default as it is installed along with IIS.
Ok... I'm sure you all can't wait to send yourself an email, so lets get on with it.
Take a look at this code:-<%
Set Mailer = Server.CreateObject("CDONTS.Newmail")
'We have created a instance of the object... lets do something with it.
Mailer.To = "youremail@yourdomain.com"
Mailer.From = "fromaddress@yourwebsite.com"
mailer.Subject = "CDONTS Example"
Mailer.Body = "Hello me!!"
'The object now has all the info it needs... lets send it.
Mailer.Send
%>
If we were to run the above code and check our inBox we will have a very basic email.
Luckily for me... the above example needs very little explanation except maybe the first line.
To use the CDONTS object, we must first create an instance of it. An instance is merely generating a copy of the object and giving it any name we want (in this case Mailer).
The CDONTS object has numerous properties (things it needs to know, or things you can find out) and a few Methods (Methods perform an action of some kind).
This list below is not meant to confuse you... it is purely for your reference. We shall cover sending more advanced email with CDONTS using some of the properties and methods (Including HTML emails) in a future article.
Happy Email Sending!!
CDONTS Properties:-
To: A string containing an email recipient address
From: To specify the senders address
CC: Carbon Copy recipient address
BCC: Blind Carbon Copy recipient address
Body: The text of the email we want to send
Importance: a number to specify message priority. 0 = low, 1=normal (default), 2 high
Subject: Used to specify the Subject line of the email
Version: This is used to retrieve the Version information of the CDONTS object
ContentBase: This property sets a base for all URLs in the message body (Used only when sending HTML emails)
ContentLocation: This property sets an absolute or relative path for all URLs in the message body(Used only when sending HTML emails)
MailFormat: Used to specify the encoding of the email. 0 = MIME format, 1= Plain text (default)
BodyFormat: This is used to set the text format of the email. 0=HTML, 1= Plain text (default)
Value: This property allows you to set additional mail headers.
CDONTS Methods:
Send: This simply send the email
AttachFile: This method adds an attachment to the message by reading a file.
AttachURL: Adds an attachment to the message and associates a URL with the attachment.
SetLocaleIDs: Sets identifiers that define locale
Return to Index
Read more:
10 Secrets To Online Success (Its All About The Customer)You've got your web site online. You're on top of the search engines. You have killer web site copy. Now all you have to do is wait for the sales to roll in right? Well . not exactly.In the last fi...
Eight Steps to Ruining Your Internet BusinessYou may not realize that there is a technique to failure. For those of you who can not fail properly, just follow these simple steps and I personally guarantee you to be a total wash-out.1. Know h...
E is for Everything . . .This article was originally published in three installments in the "Foundry Trade Journal", 2001.Just this week, a member of my audience asked me the following:"Why would a local company, with a la...
Anti Trackback and Comment Spam MethodsWhat is spam ?Spam is text or URL, in one or several exemplars, neither being waited nor wished, not having, neither directly nor from its shipper, no relationship neither with the recipient nor wi...