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

Article translations Article translations
Article ID: 186204 - View products that this article applies to.
This article was previously published under Q186204
Expand all | Collapse all

SUMMARY

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

   objNewMail
      Required. This NewMail object.

   From
      Optional. String. The full messaging address to be identified as
      the sender (for example, someone@Microsoft.com)

   To
     Optional. String. A list of full messaging addresses of recipients.
     The individual recipient addresses are separated by semicolons.
     (for example, someone@Microsoft.com)

   Subject
      Optional. String. The subject line for the message.

   Body
      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.

   Importance
      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:
          <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
          <html>
    
          <head>
          <meta http-equiv="Content-Type"
          content="text/html; charset=iso-8859-1">
          <meta name="GENERATOR"
          content="Microsoft FrontPage (Visual InterDev Edition) 2.0">
          <title>CDONTSMail</title>
          </head>
    
          <body bgcolor="#FFFFFF">
    
          <form action="CDONTSMail.asp" method="POST">
          <table border="0">
             <tr>
                <td>From:</td>
                <td><!--webbot bot="Validation"
                   b-value-required="TRUE" --><input type="text"
                   size="47" name="txtFrom"
                   value="Your internet address (Me@MyCompany.com)"></td>
             </tr>
             <tr>
                <td>To:</td>
                <td><!--webbot bot="Validation"
                   b-value-required="TRUE" --><input type="text"
                   size="47" name="txtTo"
                   value="The recipient's address (You@YourCompany.com)"></td>
             </tr>
             <tr>
                <td>Subject:</td>
                <td><input type="text" size="47" name="txtSubject"
                   value="Enter a subject here"></td>
             </tr>
             <tr>
                <td valign="top">Message:</td>
                <td><textarea name="txtMessage" rows="9" cols="45">
                   Type your message here.</textarea></td>
             </tr>
             <tr>
                <td valign="top">Importance:</td>
                <td><input type="radio" name="optImportance"
                   value="2">High<br>
                   <input type="radio" checked name="optImportance"
                   value="1">Normal<br>
                   <input type="radio" name="optImportance" value="0">Low<br>
                </td>
             </tr>
          </table>
          <p><input type="submit" name="cmdSubmit" value="Submit">
          <input type="reset" name="cmdClear" value="Clear"> </p>
          </form>
          </body>
          </html>
    						
  2. Paste the following VBScript code into a file named CDONTSMail.ASP:
          <%@ LANGUAGE="VBSCRIPT" %>
          <HTML>
          <HEAD>
          <META NAME="GENERATOR" Content="Microsoft Visual InterDev 1.0">
          <META HTTP-EQUIV="Content-Type"
           content="text/html;charset=iso-8859-1">
          <TITLE>CDONTSMail</TITLE>
    
          <%
          Sub Write(strWriteThis)
             'This subroutine just writes out whatever is
             'passed to it.
             response.write(strWriteThis & "<br>")
          end sub
    
          %>
          </HEAD>
          <BODY>
    
          <%
             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.
             strFrom=request.form("txtFrom")
             strTo=request.form("txtTo")
             strSubject = request.form("txtSubject")
             strBody=request.form("txtMessage")
             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."
             %>
          </BODY>
          </HTML>
    						
    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.

REFERENCES

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

Properties

Article ID: 186204 - Last Review: April 28, 2005 - Revision: 2.1
APPLIES TO
  • Microsoft Collaboration Data Objects 1.2 for NT Server
Keywords: 
kbhowto kbhtml kbmsg KB186204
Retired KB Content Disclaimer
This article was written about products for which Microsoft no longer offers support. Therefore, this article is offered "as is" and will no longer be updated.

Give Feedback

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com