Click here to Skip to main content
12,349,554 members (26,601 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as

Stats

280.4K views
61 bookmarked
Posted

SMTP Mail Delivery

, 28 Mar 2002
Rate this:
Please Sign up or sign in to vote.
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:

>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:

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

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

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):

myMail.BodyFormat=0

Add a file attachment:

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

Send it already!

myMail.Send

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

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

Share

About the Author

ISIS55
Web Developer Self-Employed
United States United States
No Biography provided

You may also be interested in...

Comments and Discussions

 
GeneralCDO for Hebrew Pin
Phipps Xue9-Apr-07 15:35
memberPhipps Xue9-Apr-07 15:35 
Questionhaving problem with sending email to mail.yahoo.com using CDONTS/CDO Pin
PINKS253-Apr-06 1:26
memberPINKS253-Apr-06 1:26 
AnswerRe: having problem with sending email to mail.yahoo.com using CDONTS/CDO Pin
piggalee12-Aug-06 20:56
memberpiggalee12-Aug-06 20:56 
Generalcdonts mail Pin
mimisanka21-Sep-05 19:15
membermimisanka21-Sep-05 19:15 
GeneralRe: cdonts mail Pin
yjbnew9-May-06 15:07
memberyjbnew9-May-06 15:07 
GeneralSend Email Problem Pin
EWE WEI WEN15-Sep-05 16:57
memberEWE WEI WEN15-Sep-05 16:57 
Generalsending email through SMTP Pin
aa_mm28-Aug-05 21:10
memberaa_mm28-Aug-05 21:10 
GeneralRe: sending email through SMTP Pin
Sherri Gallagher24-Aug-15 7:54
memberSherri Gallagher24-Aug-15 7:54 
GeneralCDONT SMTP RELAY Pin
Anonymous22-Jun-04 20:46
sussAnonymous22-Jun-04 20:46 
GeneralUsing CDONTS But not getting any email Pin
Anonymous28-Apr-04 19:11
sussAnonymous28-Apr-04 19:11 
GeneralBody part is not accepted... Pin
Omar Díaz15-Apr-04 6:32
sussOmar Díaz15-Apr-04 6:32 
GeneralRe: Body part is not accepted... Pin
cruzagr33-Jan-05 7:59
susscruzagr33-Jan-05 7:59 
GeneralSMTP Setup Pin
jdj Locasta6-Jan-04 6:25
memberjdj Locasta6-Jan-04 6:25 
GeneralCDO for windows 2003 servers Pin
psepesi4-Nov-03 16:46
susspsepesi4-Nov-03 16:46 
GeneralRe: CDO for windows 2003 servers Pin
erikalee9-Nov-03 20:02
membererikalee9-Nov-03 20:02 
GeneralRe: CDO for windows 2003 servers Pin
Arkadiusz R. Jagielski7-Apr-04 12:28
memberArkadiusz R. Jagielski7-Apr-04 12:28 
GeneralCDO for windows 2003 servers Pin
psepesi4-Nov-03 16:44
susspsepesi4-Nov-03 16:44 
GeneralCDONTS giving warnings Pin
Monte Kottman22-Oct-03 5:04
sussMonte Kottman22-Oct-03 5:04 
GeneralPlz Help me, how ca n i do the same in VC++ Pin
Azhar Javaid22-Aug-03 1:43
memberAzhar Javaid22-Aug-03 1:43 
GeneralRe: Plz Help me, how ca n i do the same in VC++ Pin
dharani21-Sep-03 19:58
memberdharani21-Sep-03 19:58 
GeneralRe: Plz Help me, how ca n i do the same in VC++ Pin
Dimitris Vassiliades17-Mar-04 3:51
memberDimitris Vassiliades17-Mar-04 3:51 
Generalnot a cdont but a SMTPsvg.Mailer Pin
flashermx16-Aug-03 16:42
memberflashermx16-Aug-03 16:42 
GeneralSample for Attachment Pin
Pinakin7-Aug-03 17:36
memberPinakin7-Aug-03 17:36 
QuestionHow CDONTS work in VC++ Pin
RennyAshay6-Aug-03 18:36
memberRennyAshay6-Aug-03 18:36 
Questionhow make it work with XP Pin
moh41010-Jun-03 6:02
membermoh41010-Jun-03 6:02 
AnswerRe: how make it work with XP Pin
marriola6-Aug-03 7:01
membermarriola6-Aug-03 7:01 
GeneralCDONTS not sending email Pin
meghana_parikh@hotmail.com8-May-03 13:31
membermeghana_parikh@hotmail.com8-May-03 13:31 
GeneralRe: CDONTS not sending email Pin
Anonymous4-Aug-04 23:39
sussAnonymous4-Aug-04 23:39 
Generalsending e-mail whith cdonts Pin
Anonymous28-Apr-03 6:31
sussAnonymous28-Apr-03 6:31 
GeneralRe: sending e-mail whith cdonts Pin
Arkadiusz R. Jagielski7-Apr-04 12:26
memberArkadiusz R. Jagielski7-Apr-04 12:26 
GeneralCDONTS Pin
alex197731-Mar-03 23:47
sussalex197731-Mar-03 23:47 
GeneralRe: CDONTS Pin
Dimitris Vassiliades1-May-03 8:34
memberDimitris Vassiliades1-May-03 8:34 
Generaldon't want incoming e-mails Pin
Bill coulter20-Feb-03 3:08
sussBill coulter20-Feb-03 3:08 
Generalemail with ASP Pin
Areen Ruman31-Jan-03 2:57
sussAreen Ruman31-Jan-03 2:57 
GeneralRe: email with ASP Pin
sm808216-Jun-03 12:11
membersm808216-Jun-03 12:11 
GeneralRe: email with ASP Pin
Arkadiusz R. Jagielski7-Apr-04 12:24
memberArkadiusz R. Jagielski7-Apr-04 12:24 
GeneralRe: email with ASP Pin
Anonymous11-Jul-04 19:39
sussAnonymous11-Jul-04 19:39 
Generaltest sent email Pin
yot8-Jan-03 5:13
memberyot8-Jan-03 5:13 
GeneralGetting dynamic values from a database Pin
jimmyeprince31-Dec-02 11:09
sussjimmyeprince31-Dec-02 11:09 
Generalerror in open attachements Pin
logu23-Sep-02 1:34
susslogu23-Sep-02 1:34 
GeneralCDO for Windows 2000 Pin
Anonymous20-Sep-02 6:27
sussAnonymous20-Sep-02 6:27 
GeneralReceiving e-mails Pin
A R10-Sep-02 8:55
sussA R10-Sep-02 8:55 
GeneralRe: Receiving e-mails Pin
Ryan Binns27-Mar-03 18:49
memberRyan Binns27-Mar-03 18:49 
GeneralRe: Receiving e-mails Pin
Anonymous29-Jan-04 8:28
sussAnonymous29-Jan-04 8:28 
GeneralRe: Receiving e-mails Pin
Ryan Binns30-Jan-04 1:11
memberRyan Binns30-Jan-04 1:11 
GeneralRe: Receiving e-mails Pin
Anonymous12-Aug-03 21:40
sussAnonymous12-Aug-03 21:40 
GeneralRe: Receiving e-mails Pin
shwetketu6-Feb-04 9:06
sussshwetketu6-Feb-04 9:06 
Generalrunning on windows2000 proffisional and problem on windows 2000 server Pin
Dodi--ASP--Dodi14-Jul-02 22:04
sussDodi--ASP--Dodi14-Jul-02 22:04 
GeneralRe: running on windows2000 proffisional and problem on windows 2000 server Pin
otherwise19-Jul-03 23:25
memberotherwise19-Jul-03 23:25 
GeneralCDONTS Not Working Pin
Anonymous13-Jul-02 14:47
sussAnonymous13-Jul-02 14:47 

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.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.160621.1 | Last Updated 29 Mar 2002
Article Copyright 2002 by ISIS55
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid