Article
Sending eMail in ASP
Sending email in Active Server Pages isn’t at complex as it seems. All you need is an ASP Page that contains your code, a host that supports ASP and CDONTS (Collaborative Data Objects for Windows NT Server), and a basic knowledge of Active Server Pages.
CDONTS provides you with objects and classes that enable you to send email from an ASP page. CDONTS only works on Windows NT/2000 Operating Systems, but it has powerful functions, allowing you to:
- attach files while sending email,
- send email in HTML Format,
- use the Carbon Copy(CC) and Blind Carbon Copy(BCC) functions as in any email client,
- set email priority
Create CDONTS
First of all, we must create an instance of the CDONTS on the server using this code:
<%
Set Mail=Server.CreateObject(“CDONTS.NewMail”)
%>
In the above code, you can replace Mail with any other variable, but you must be sure to use that variable constantly. Now that we’ve created an instance of CDONTS on the server, we need to input the required values.
Input Your Values
The first input should be the Recipient to whom we’ll send the email. To add the Recipient address, use:
<%
Mail.to=” me@mydomain.com”
%>
Mail.to consists of the same variable that we used to name the instance of our CDONTS.NewMail The to after the . tells the object the address to which the email should be sent. So now our code looks like this:
<%
Set Mail=Server.CreateObject(“CDONTS.NewMail”)
Mail.to=” me@mydomain.com”
%>
Now we need to tell the object the email address of the Sender, using:
<%
Mail.From=” testing-my@SP-Script.com”
%>
The From field after Mail. indicates the email address of the Sender. The email address should always appear in quotes. With this addition, our code becomes:
<%
Set Mail=Server.CreateObject(“CDONTS.NewMail”)
Mail.To=”me@mydomain.com”
Mail.From=”testing-my@SP-Script.com”
%>
By now you’re clear on the concept of using the main classes, so let’s look at how to add the Subject line to the email. If you haven’t already guessed, this is how to do it:
<%
Mail.Subject=”Just testing my script”
%>
Now the code is:
<%
Set Mail=Server.CreateObject(“CDONTS.NewMail”)
Mail.To=”me@mydomain.com”
Mail.From=”testing-my@SP-Script.com”
Mail.Subject=”Just testing my script”
%>
All that's left now is the content of the email, which we add like this:
<%
Mail.Body=”Hey! I am sending this email through an ASP Page, and
guess what? I haven’t learnt much yet, but know that ASP is very
powerful.”
%>
Omair operates