Microsoft KB Archive/186204

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

Article ID: 186204

Article Last Modified on 4/28/2005

-

APPLIES TO


 * Microsoft Collaboration Data Objects 1.2 for NT Server

-



This article was previously published under Q186204



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.

  Copy and paste the following HTML code into a file named CDONTSMail.HTM: <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">

  CDONTSMail



     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" 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 & " ") 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. </li> 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:

<ol style="list-style-type: lower-alpha;"> On your IIS computer, open the Microsoft Management Console (MMC).</li> In the left pane, expand the "Internet Information Server" section.</li> In the left pane, select and expand your IIS server.</li> In the right pane, right-click "Default SMTP server" and select "Properties"</li> Select the "Delivery" tab.</li> In the "Fully Qualified Domain Name" text box, enter the IIS computer name.</li> In the "Smart Host" text box, enter the name of your SMTP server.</li></ol> </li> 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.</li></ol>

<div class="references_section">