Exploring Collaboration Data Objects for Windows NT Server (CDONTS) and the newer Collaboration Data Objects for Windows 2000 (CDO or CDOSYS) which enables messaging and email on IIS.
See also "How to migrate the Collaboration Data Objects for NTS applications to Microsoft Collaboration Data Objects for Windows 2000" [support.microsoft.com/?kbid=810702] for migrating from CDONTS to CDO (aka CDOSYS; Microsoft Collaboration Data Objects for Windows 2000).
The main differences:
CDONTS.NewMailis nowCDO.Message.myMail.Body = strBodyis nowmyMail.TextBody = strBody.Here is an example of using CDOSYS in JavaScript:
function gSendEmail(email) { //Using CDOSYS sending email thru a remote SMTP server: var objMessage=Server.CreateObject("CDO.Message"); objMessage.Subject=email.strSubject; objMessage.From=email.strFrom; objMessage.To=email.strTo; //EG: "sam@gmail.com, sue@gmail.com" if ('strCc' in email) objMessage.Cc=email.strCc; if ('strBcc' in email) objMessage.Bcc=email.strBcc; if (email.blnIsHtml) objMessage.HtmlBody=email.strBody; //EG: "<p>Hello <world!></p>" else objMessage.TextBody=email.strBody; //EG: "Hello world!"; if ('strAttachment' in email) objMessage.AddAttachment(email.strAttachment); //EGs: "http://www.fake.com/hi.jpg" or "c:\y.pdf" objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing")=2; objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver")="smtp.fake.com"; objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport")=465; objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout")=30; objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl")=true; objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate")=1; objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusername")="faker@fake.com"; objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword")="F0o-B4r_!"; objMessage.Configuration.Fields.Update(); objMessage.Send(); }See also: "About CDO for Windows 2000" [msdn.microsoft.com/library/default.asp?url=/library/en-us/cdosys/html/ecdb51f4-5ba0-46d8-9c7c-7e4154a18f50.asp] and "A Beginner's Guide to Sending Email from an ASP Page" [http://www.devguru.com/features/tutorials/CDONTS/cdonts.html].
CDONTS interfaces with the SMTP (Simple Mail Transfer Protocol) server component of Microsoft IIS (Internet Information Server) version 4.0 and later.
The object model for CDONTS is as follows.
The only CDONTS object I am concerned with is NewMail, which enables ASP pages to send email.
If you run into problems, then often times it is fixed by setting RWX permissions on the cdonts.dll and cdosys.dll in C:\WINNT\system32, as well as the C:\Inetpub\mailroot\Pickup directory.
Only a few lines of code are needed to send an email via the CDONTS NewMail object. EG:
Set objNewMail = CreateObject("CDONTS.NewMail")
objNewMail.Send "sender@fake.com", "receiver@unreal.com", "My Subject", _
"Body of message", 0 'Importance 0=low, 1=default, 3=high
Set objNewMail = Nothing 'NewMail objects cannot be reused Response.Write "Email has been sent"
Email is often generated via a form. EG:
<%
Sub sendmail(fromWho, toWho, Subject, Body)
Dim myMail
Set myMail = Server.CreateObject("CDONTS.Newmail")
myMail.From = fromWho
myMail.To = toWho
myMail.Subject = Subject
myMail.Body = Body
myMail.Send
End Sub
fromWho = Trim( Request.Form( "fromWho") )
toWho = Trim( Request.Form( "toWho") )
Subject = Trim( Request.Form( "Subject" ) )
Body = Trim( Request.Form( "Body") )
myMail.AttachFile "\\server\subdir\file.xls", "renamedFile.xls"
'Or Call myMail.AttachFile("\\server\subdir\file.xls", "renamedFile.xls")
If toWho <> "" Then
sendMail fromWho, toWho, Subject, Body
Response.redirect "confirmation.html"
End If
%>
<html>
<head><title>Email Form</title></head>
<form method="post" action="<%=Request.ServerVariables("SCRIPT_NAME")%>">
<br />TO: <input name="toWho" type="text" size="40">
<br />FROM: <input name="fromWho" type="text" size="40">
<br />SUBJECT: <input name="Subject" type="text" size="40">
<br /><textarea name="Body" cols="40" rows="5"></textarea>
<br /><input type="submit" value="Send Mail">
</form>
</html>
All the properties are write-only.
Email lists delimited by semicolons.
| Name | Type | Note |
|---|---|---|
| Bcc | String | Blind carbon copied email list. |
| Body | IStream object or String | plain text or HTML. |
| BodyFormat | Long | 0=HTML allowed in Body. 1=plain text (default). |
| Cc | String | Carbon copied email list. |
| ContentBase | String | Prefixed to Content Location if Content Location provides relative path. EG: http://www.fake.com/.See also RFC 2110 and MHTML (MIME HTML). |
| ContentLocation | String | Prefixed to URLs in Body that use relative URLs. EG: http://www.fake.com/subdir/. EG: subdir/.Note that relative URLs in the Body can reference attachments via AttachURL(). |
| From | String | Only 1 email is allowed for From. |
| Importance | Long | 0=low. 1=normal (default). 3=high. |
| MailFormat | Long | 0=MIME.
1=uninterrupted plain text (default). Inserts line breaks for lines lengths greater than 74 characters. See also RFC 1341. |
| Subject | String | |
| To | String | To email list. |
| Value | String | Syntax: objNewMail.Value(header) = strHdrValue.Common headers include: File, Reference, Keywords, Reply-To, Confidential. |
| Version | String | Returns the version of the CDONTS. Returns "1.2.1" [Ref 2003-07]. |
| Name | Parameters | Note |
|---|---|---|
| AttachFile | Source as Object or String,
(optional) NewFileName as String, (optional) EncodingMethod as Long |
Adds an attachment to the email. Source is a physical location. EG: Server.MapPath("file.txt"). EG: c:\subdir\file.txt.The EncodingMethod: 0=Attachment is UUEncode format (default). 1=Attachment is base 64 format. |
| AttachURL | Source as Object or String,
ContentLocation as String, (optional) ContentBase as String, (optional) EncodingMethod as Long |
Adds an attachment to the email but also allows the Body to reference the attachment with a relative path. |
| Send | (optional) From as String,
(optional) To as String, (optional) Subject as String, (optional) Body as Object or String, (optional) Importance as Long |
If the To property and the To parameter of Send() are both specified, then the email is sent to both lists. Only 1 email is allowed for From. |
| SetLocaleIDs | CodePageID as Long | Changes the code page ID from the default to the one specified. |
Page Modified: (Hand noted: 2008-03-31 18:49:07Z) (Auto noted: 2008-03-31 18:48:24Z)