Click here to Skip to main content
15,884,298 members
Articles / Programming Languages / ASP
Article

SMTP Mail Delivery

Rate me:
Please Sign up or sign in to vote.
4.45/5 (12 votes)
28 Mar 20024 min read 316.5K   61   77
A beginner's guide to SMTP automated mail delivery with the CDONTS library.

Introduction

Handling email is a very important part of every active website. Automating mail delivery could be extremely useful and could have many uses such as:

  • Online order verification.
  • Creating a mailing list to update customers of recent news/sales.
  • Responding to a software download.
  • And the list goes on...

The reasons may vary, but the need is the same: your site should be able to send email automatically. And this is exactly what you're going to learn in this article - using the CDONTS library to send email.

Important notice: the CDONTS library is only applicable to NT users, it will not work for PWS users.

The Importance of Automated Mail Response

Just a moment before we delve into the techy stuff, I'd like to emphasize the importance of an automated mail response. When a user gets an email notification from your site he gets the feeling that someone has answered him, he has someone to talk to, this isn't yet another dead-end sale. The response to the user's action gives him a sense of security. Automated mail response is an important tool - use it wisely.

Let the learning begin!

The SMTP Service

SMTP - Simple Mail Transfer Protocol - is a Service on the NT OS. It is installed with the IIS (if you choose it from the list of components).

How can you know whether it is installed on your server or not? Simple. Call it and see if you get an answer! Choose Start > Run from the Start menu and type telnet [ServerName] 25.

Check for the STMP service

Replace ServerName with your server name of course. 25 is the port number SMTP listens to.

If it's installed you should get an answer similar to this:

none
220-MyServer Microsoft SMTP MAIL ready at
Sun, 24 March 2002 18:12:21 - 0500 Version 5.5.1877.977.9
220 WSMTP Spoken here

If not, then you probably don't have SMTP installed on your server. To install it run the NT Option Pack installation, and choose the appropriate option.

CDONTS

The CDONTS library - Collaboration Data Objects for NT Server, which also comes with the NT Option Pack, provides very useful objects for delivering/receiving mail through SMTP. Note that there is another library called CDO, which is much richer and provides a lot more options. It comes with the Microsoft Exchange Server. The CDONTS library is simpler to use, and with it you can send mail within a few lines of code.

Lets get on with it already!

The NewMail Object

The CDONTS library contains a number of objects, but we will focus on the simplest object: NewMail. It is used for quick and simple mail delivery.

Lets quickly review the NewMail object properties:

Property Explanation
Bcc Blind Carbon Copy (additional delivery address)
Body The message body
BodyFormat Message format: 0-HTML 1-Text
Cc Carbon Copy (additional delivery address)
ContentBase Base path for files in the message
ContentLocation Relative base path for files in the message
From Sender address
Importance Priority: 0 to 3
MailFormat Delivery method: 0-Mime 1-Text
Subject Message subject
To Receiver's address
Value Additional message headline
Version CDONTS version

There are 3 options to add receivers' addresses:

  1. To - the simplest way, this is the primary receiver address.
  2. CC - additional receiver (the receiver can see who else received the message).
  3. BCC - additional receiver (the receiver can't see who else received the message, it will look as if it was sent only to him).

Now lets review the NewMail object methods:

Method Explanation
AttachFile Attach a file to the message
AttachURL Attach URL to the message
Send Send the message
SetLocaleIDs Set a Code Page for the message

Onward!

Sending the Mail!

Ok, we've come this far now lets send a message!

Create myMail - a NewMail object:

VBScript
Set myMail = Server.CreateObject("CDONTS.NewMail")

Now set the message properties: receiver's address, sender's address, message content, subject and so on.

VBScript
myMail.To = "bill_g@yahoo.com"
myMail.Body = "Hey Bill, how come you're using yahoo mail service?"
myMail.From = "faq@your_company.com"
myMail.Subject = "Testing"

Set the message format to MIME (Multipurpose Internet Mail Extension):

VBScript
myMail.BodyFormat=0

Add a file attachment:

VBScript
Call myMail.AttachFile("\\server\bill_photos\bill_wife_nude.jpg", "BILL_WIFE_NUDE.JPG")

Send it already!

VBScript
myMail.Send

Now don't forget to clear the object...

VBScript
Set myMail=nothing

Cut! And we're done.

Summary

So, what have we done so far?

  • We discussed the importance of automated mail response.
  • We got the SMTP Service up and running.
  • We reviewed the NewMail object from the CDONTS library.
  • And we sent out a simple message, though I assume you'll improve the code to suit your needs.

Wrap it up guys.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer Self-Employed
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralRe: CDONTS Not Working Pin
Anonymous10-Jan-03 8:40
Anonymous10-Jan-03 8:40 
GeneralRe: CDONTS Not Working Pin
Ryan Binns27-Mar-03 18:52
Ryan Binns27-Mar-03 18:52 
GeneralRe: CDONTS Not Working Pin
marriola6-Aug-03 7:03
marriola6-Aug-03 7:03 
Generalcdonts Pin
Shotgun22-Jun-02 4:17
Shotgun22-Jun-02 4:17 
Generaladding a from name Pin
18-Jun-02 2:41
suss18-Jun-02 2:41 
GeneralRe: adding a from name Pin
18-Jun-02 2:42
suss18-Jun-02 2:42 
Generalobject CDONTS Pin
2-Jun-02 22:49
suss2-Jun-02 22:49 
Generalhelp me find errors Pin
thngan10-Sep-03 18:10
thngan10-Sep-03 18:10 
GeneralShow me all the properties of CDONTS Pin
2-Jun-02 18:25
suss2-Jun-02 18:25 
GeneralSending to multiple people without them knowing Pin
19-May-02 22:42
suss19-May-02 22:42 
GeneralRe: Sending to multiple people without them knowing Pin
19-May-02 22:43
suss19-May-02 22:43 
GeneralRe: Sending to multiple people without them knowing Pin
ISIS5520-May-02 10:14
ISIS5520-May-02 10:14 
GeneralSending to multiple people without them knowing Pin
19-May-02 22:41
suss19-May-02 22:41 
GeneralRe: Sending to multiple people without them knowing Pin
Figuerres26-May-03 6:15
Figuerres26-May-03 6:15 
QuestionHow to use CDO to send messages. Pin
Tili14-May-02 11:30
Tili14-May-02 11:30 
QuestionCan you help me? Pin
13-Apr-02 23:03
suss13-Apr-02 23:03 
AnswerSorry, it's ok now. Pin
13-Apr-02 23:10
suss13-Apr-02 23:10 
GeneralSMTP Primer Pin
Roger Wright12-Apr-02 8:52
professionalRoger Wright12-Apr-02 8:52 
GeneralRe: SMTP Primer Pin
ISIS5512-Apr-02 14:21
ISIS5512-Apr-02 14:21 
GeneralGood work Sasson! Pin
Nish Nishant28-Mar-02 14:36
sitebuilderNish Nishant28-Mar-02 14:36 
GeneralRe: Good work Sasson! Pin
ISIS5529-Mar-02 1:20
ISIS5529-Mar-02 1:20 
GeneralVery nice... but Pin
David Wengier28-Mar-02 11:00
David Wengier28-Mar-02 11:00 
GeneralNice Pin
Jon Sagara28-Mar-02 8:13
Jon Sagara28-Mar-02 8:13 
GeneralRe: Nice Pin
ISIS5528-Mar-02 8:23
ISIS5528-Mar-02 8:23 
GeneralRe: Nice Pin
Jon Sagara28-Mar-02 9:54
Jon Sagara28-Mar-02 9:54 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.