Microsoft KB Archive/248687

From BetaArchive Wiki
Knowledge Base

How to send mail from an Active Server Page by using CDOEX with Exchange 2000 Server or Exchange Server 2003

Article ID: 248687

Article Last Modified on 4/4/2006


  • Microsoft Exchange 2000 Server Standard Edition
  • Microsoft Exchange Server 2003 Enterprise Edition
  • Collaboration Data Objects for Exchange 2000, when used with:
    • Microsoft Windows Server 2003, Enterprise Edition (32-bit x86)

This article was previously published under Q248687


This article demonstrates how to send an e-mail message from an Active Server Pages page by using the Collaboration Data Objects for Exchange 2000 (CDOEX.dll). The sample code provided below takes input from the user and sends an e-mail message by using CDOEX.


This article assumes that you have:

  • Microsoft Windows 2000 or Microsoft Windows Server 2003
  • Microsoft Exchange 2000 Server or Microsoft Exchange Server 2003
  • Microsoft Internet Information Server (IIS) 5.0 or higher

To use the sample code, follow these steps:

  1. Create a folder under \Inetpub\wwwroot named Sendmailsample.
  2. Open Notepad.
  3. Paste the following code.

    <%@ Language=VBScript %>
    <% submit = Request.Form.Item("B1") 
    if submit = "Send" 
    Dim iMsg Set iMsg = CreateObject("CDO.Message") 
    Dim iConf Set iConf = CreateObject("CDO.Configuration") 
    Dim Flds Set Flds = iConf.Fields 
    ' 3 means that you are asking mail to be sent using Exchange Server. 
    'TODO: Change the "user" and "password" values to match your environment 
    Flds( "") = 3 
    Flds("") = "Username" 
    Flds("") = "Password" 
    Set iMsg.Configuration = iConf 
    iMsg.To = Request.Form.Item("Text1") 
    iMsg.From = "" 
    iMsg.Subject = Request.Form.Item("Text3") 
    iMsg.TextBody = Request.Form.Item("TextArea1") 
    end if %>
            <meta NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
        <body bgcolor="black">
            <% if submit = "Send" then %>
            <font color="white"><b><u>Mail Sent</u></b></font>
            <% else%>
            <form name="mnFrm" method="post" action="SendMail.asp" ID="Form1">
                    <base target="_top">
                    <TABLE cellPadding="4" cellSpacing="0" class="Nav2" ID="Table1">
                            <TD><font color="red">To</font>
                            <TD><INPUT name="Text1" size="58" style="HEIGHT: 22px; WIDTH: 500px" ID="Text1"></TD>
                            <TD><LABEL><font color="red">Subject </font></LABEL>
                            <TD><INPUT border="0" name="Text3" size="58" style="HEIGHT: 22px; WIDTH: 500px" ID="Text2"></TD>
                            <TD vAlign="top"><LABEL><font color="red">Body</font> </LABEL>
                            <TD><TEXTAREA cols="63" name="TextArea1" rows="30" style="BACKGROUND-COLOR: white; HEIGHT: 165px; WIDTH: 590px"
                    <INPUT name="B1" type="submit" value="Send" ID="Submit1"></P>
            <%end if %>
  4. Save the file as Sendmail.asp in the Sendmailsample folder that you created above.
  5. Open Internet Service Manager.
  6. In the properties for the Sendmailsample folder, set the security properties to Digest Authentication for Windows Domain Servers and Integrated Windows Authentication.
  7. Load the page in IIS.
  8. Fill in the form, and then click Send.

Keywords: kbhowto kbmsg KB248687