How to use CDONTS to collect and mail information from a user

Zastarané vyhlásenie týkajúce sa obsahu databázy KB

Tento článok sa týka produktov, ku ktorým už spoločnosť Microsoft neposkytuje technickú podporu. Preto sa tento článok ponúka tak, „ako je“, a už nebude aktualizovaný.


This article contains an example that describes how to collect information from a user on a .HTM page, and then use that information to send mail to a recipient using Collaboration Data Objects for Windows NT Server (CDONTS) over SMTP. This article includes sample code for the HTM and ASP files as well as information on how to configure your Microsoft Management Console (MMC) Default SMTP Server.

More Information

The syntax for sending mail with the NewMail object of CDONTS is as follows:

objNewMail.Send([From][, To][, Subject][, Body][, Importance] )

Required. This NewMail object.

Optional. String. The full messaging address to be identified as
the sender (for example,

Optional. String. A list of full messaging addresses of recipients.
The individual recipient addresses are separated by semicolons.
(for example,

Optional. String. The subject line for the message.

Optional. IStream object or String. The text of the message. Only
C/C++ and Java programs can use an IStream object for the Body
parameter. They should pass an IUnknown object that returns an
IStream interface in response to QueryInterface. Microsoft Visual
Basic supports the IDispatch interface and not IUnknown, so it
cannot use an IStream object.

Optional. Long. The importance associated with the message, High,
Normal or Low. This article sets the required value depending upon
which option button the user selects.

  1. Copy and paste the following HTML code into a file named CDONTSMail.HTM:

    <meta http-equiv="Content-Type"
    content="text/html; charset=iso-8859-1">
    <meta name="GENERATOR"
    content="Microsoft FrontPage (Visual InterDev Edition) 2.0">

    <body bgcolor="#FFFFFF">

    <form action="CDONTSMail.asp" method="POST">
    <table border="0">
    <td><!--webbot bot="Validation"
    b-value-required="TRUE" --><input type="text"
    size="47" name="txtFrom"
    value="Your internet address ("></td>
    <td><!--webbot bot="Validation"
    b-value-required="TRUE" --><input type="text"
    size="47" name="txtTo"
    value="The recipient's address ("></td>
    <td><input type="text" size="47" name="txtSubject"
    value="Enter a subject here"></td>
    <td valign="top">Message:</td>
    <td><textarea name="txtMessage" rows="9" cols="45">
    Type your message here.</textarea></td>
    <td valign="top">Importance:</td>
    <td><input type="radio" name="optImportance"
    <input type="radio" checked name="optImportance"
    <input type="radio" name="optImportance" value="0">Low<br>
    <p><input type="submit" name="cmdSubmit" value="Submit">
    <input type="reset" name="cmdClear" value="Clear"> </p>
  2. Paste the following VBScript code into a file named CDONTSMail.ASP:
          <%@ LANGUAGE="VBSCRIPT" %>
    <META NAME="GENERATOR" Content="Microsoft Visual InterDev 1.0">
    <META HTTP-EQUIV="Content-Type"

    Sub Write(strWriteThis)
    'This subroutine just writes out whatever is
    'passed to it.
    response.write(strWriteThis & "<br>")
    end sub


    Dim myCDONTSMail
    Dim strFrom
    Dim strTo
    Dim strSubject
    Dim strMessage
    Dim lngImportance

    'The following variable assignments are not required
    'they are just here to make interpretation of the
    'myCDONTSMail.Send line easier. You could put the
    'Request.Form statements in the .Send line to cut down
    'on the amount of code in the file.
    strSubject = request.form("txtSubject")
    lngImportance = request.form("optImportance")

    'The following four lines of code are just here for test
    'purposes to see what variables have been pulled in from the
    'HTM form.
    Write("strFrom = " & strFrom)
    Write("strTo = " & strTo)
    Write("strSubject = " & strSubject)
    Write("strMessage = " & strBody)
    Write("Importance = " & lngImportance)

    Set myCDONTSMail = CreateObject("CDONTS.NewMail")

    myCDONTSMail.Send strFrom,strTo,strSubject,strBody,lngImportance

    Set myCDONTSMail = Nothing
    Write "Mail has been sent."
    NOTE: The NewMail object becomes invalid upon successful completion of the Send method, and you cannot reuse it for another message. You should Set it to Nothing to release the memory. Attempted access to a sent NewMail object results in a return of CdoE_INVALID_OBJECT.
  3. Steps to Configure your Internet Information Server (IIS). In order to send mail from your IIS server via your SMTP server (assuming that they are different computers), complete the following steps:

    1. On your IIS computer, open the Microsoft Management Console (MMC).
    2. In the left pane, expand the "Internet Information Server" section.
    3. In the left pane, select and expand your IIS server.
    4. In the right pane, right-click "Default SMTP server" and select "Properties"
    5. Select the "Delivery" tab.
    6. In the "Fully Qualified Domain Name" text box, enter the IIS computer name.
    7. In the "Smart Host" text box, enter the name of your SMTP server.
  4. Run the CDONTSMail.htm file in your browser, enter the required information, and then select the Submit button.

    NOTE: The code above requires you to enter a value in the From and To fields.


Collaboration Data Objects Help; search on "Collaboration Data Objects for NTS Component"; topic: "NewMail Object (CDONTS Library)"

ID článku: 186204 – Posledná kontrola: 22. 9. 2009 – Revízia: 1