SUMMARY
This step-by
step article describes how to migrate existing code based on the CDONTS object
model to CDOSYS.
You can use the Cdonts.dll and Cdosys.dll object
libraries to create and process e-mail by using Internet standard formats and
protocols. Collaboration Data Objects for NTS (CDONTS) was originally
implemented to use with Microsoft Commercial Internet Server (MCIS), and was
included in the Windows NT Option Pack. CDONTS was also included as part of
Windows 2000 for compatibility with Windows NT. CDONTS is not included with
Microsoft Windows XP and subsequent releases of Windows. Microsoft
Collaboration Data Objects for Windows 2000 (CDOSYS) was implemented and
included as a Windows 2000 operating system component. The existing code that
is based on CDONTS must migrate to CDOSYS.
Back to the topFeature
comparison
The following table compares operating system (OS) support and
feature support in the Cdonts.dll and the Cdosys.dll libraries.
Feature | CDONTS | CDOSYS | Notes |
Windows NT support | yes | no | Neither
included with OS |
Windows 2000 support | yes | yes | Both
included with OS |
Windows XP support | no | yes | CDOSYS only
included with OS |
Exchange server support | yes | yes | |
Send mail | yes | yes | |
Post to newsgroup | no | yes | |
Send (post) by using Simple Mail Transfer Protocol (SMTP)
Network News Transfer Protocol (NNTP) port
| no | yes | |
MIME and Uuencode message formats
| yes | yes | |
Explicit control of MIME body part structure, encoding,
charset, and others. | no | yes | |
HTML and MHTML support | yes | yes | |
List / read local drop directory
| no | yes | |
List / read inbox through POP3
| yes | no | |
Transport event sink support
| no | yes | |
Reply and forward
functions | no | yes | |
Back to the
topExamples
The following examples demonstrate how to perform the same task
by using CDONTS and by using CDOSYS. Each of the following examples describes a
feature that both libraries have, and then gives sample code for implementing
the feature in each library. These code samples were verified by using Windows
2000 Service Pack 2 (SP2) and the following versions of the libraries:
- CDONTS 6.0.3939.0
- CDOSYS 6.0.3943.3
Simple send
This example is the most popular use for both libraries. In this
case, both libraries write the message to the pickup directory of the SMTP
server. The directory path is read from the local metabase. CDONTS example
set m =
CreateObject("CDONTS.NewMail") m.Send "user1@company.com", _
"user2@company.com", _ "test 1", _ "hello there"
CDOSYS example
Set m =
CreateObject("CDO.Message") m.From = "user1@company.com" m.To =
"user2@company.com" m.Subject = "test 1" m.TextBody = "hello there"
m.send
Back to the topSend HTML body
The following examples put HTML body text in the message.
Otherwise, these examples are similar to the "Simple Send" examples. In both
sets of examples, MIME multipart/alternative message format is used. Also, a
plain text body is automatically created from the HTML. The plain text body is
included as a text/plain body part.CDONTS example
sHTML = "<html><body><font
color=""#FF0000"">" & _ "hello,
Red</font></body></html>" Set m =
CreateObject("CDONTS.NewMail") m.MailFormat = 0 ' CdoMailFormatMime
m.BodyFormat = 0 ' CdoBodyFormatHTML m.Send "user1@company.com", _
"user2@company.com", _ "test 1", _ sHTML
CDOSYS
example
sHTML = "<html><body><font
color=""#FF0000"">" & _ "hello,
Red</font></body></html>" Set m = CreateObject("CDO.Message")
m.From = "user1@company.com" m.To = "user2@company.com" m.Subject = "test 1"
m.HtmlBody = sHTML m.send
Back to the topSend with an attachment in MIME
format
CDONTS example
Set m = CreateObject("CDONTS.NewMail") m.MailFormat = 0 ' CdoMailFormatMime
m.AttachFile "d:\ptsp\test\test.doc" m.Send "user1@company.com", _
"user2@company.com", _ "test.doc", _ "Here is the document you
requested"
CDOSYS example
Set m
= CreateObject("CDO.Message") m.From = "user1@company.com" m.To =
"user2@company.com" m.Subject = "test.doc" m.TextBody = "Here is the document
you requested." m.AddAttachment "file://d:\ptsp\test\test.doc"
m.send
Back to the topSend with an attachment in Uuencode format
For both libraries, to send the message with an attachment in
Uuencode, change a property on the message to change the format. CDONTS example
Set m =
CreateObject("CDONTS.NewMail") m.MailFormat = 1 ' CdoMailFormatText
m.AttachFile "d:\ptsp\test\test.doc" m.Send "user1@company.com", _
"user2@company.com", _ "test.doc", _ "Here is the document you requested"
CDOSYS example
Set m =
CreateObject("CDO.Message") m.MimeFormatted = false m.From =
"user1@company.com" m.To = "user2@company.com" m.Subject = "test.doc"
m.TextBody = "Here is the document you requested." m.AddAttachment
"file://d:\ptsp\test\test.doc" m.send
Back to the topSend Unicode message text
This example includes a Unicode character (the Euro symbol, ?,
Unicode code point 0x20ac) in the display name of the recipient and in the
message text. In both examples, "?" is encoded into the
utf-7 CharSet property. CDONTS must use the
CP_UTF7=65000 constant. For CDOSYS, the
CharSet name is
unicode-1-1-utf-7. CDONTS example
Set s = CreateObject("CDONTS.Session") S.LogonSMTP "User 1",
"user1@company.com" s.SetLocaleIDs 65000 ' cpUTF7 Set m = s.Outbox.Messages.Add
m.MessageFormat = 0 ' CdoMime set r = m.Recipients.Add 'r.address =
"user2@company.com" r.name = "Joe ?" r.address = "<joe.euro@company.com>"
m.Subject = "Unicode content" m.Text = "That will be ?5, please."
m.Send
CDOSYS example
set m =
CreateObject("CDO.Message") m.From = "User1 <user1@company.com>" m.To =
"Joe ? <joe.euro@company.com>" m.Subject = "Unicode content" set b =
m.bodypart b.charset = "unicode-1-1-utf-7" m.textbody = "That will be ?5,
please." m.send
Back to the
top