Registrations are now open. Join us today!
There is still a lot of work to do on the wiki yet! More information about editing can be found here.
Already have an account?

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



APPLIES TO

  • 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

SUMMARY

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.

MORE INFORMATION

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" 
    
    then 
    
    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( "http://schemas.microsoft.com/cdo/configuration/sendusing") = 3 
    
    Flds("http://schemas.microsoft.com/cdo/configuration/user") = "Username" 
    
    Flds("http://schemas.microsoft.com/cdo/configuration/password") = "Password" 
    
    Set iMsg.Configuration = iConf 
    
    iMsg.To = Request.Form.Item("Text1") 
    
    iMsg.From = "administrator@domain.com" 
    
    iMsg.Subject = Request.Form.Item("Text3") 
    
    iMsg.TextBody = Request.Form.Item("TextArea1") 
    
    iMsg.Send 
    
    end if %>
    <html>
        <head>
            <meta NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
        </head>
        <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">
                <P>
                    <base target="_top">
                    <TABLE cellPadding="4" cellSpacing="0" class="Nav2" ID="Table1">
                        <tr>
                            <TD><font color="red">To</font>
                            </TD>
                            <TD><INPUT name="Text1" size="58" style="HEIGHT: 22px; WIDTH: 500px" ID="Text1"></TD>
                        </tr>
                        <TR>
                            <TD><LABEL><font color="red">Subject </font></LABEL>
                            </TD>
                            <TD><INPUT border="0" name="Text3" size="58" style="HEIGHT: 22px; WIDTH: 500px" ID="Text2"></TD>
                        </TR>
                        <TR>
                            <TD vAlign="top"><LABEL><font color="red">Body</font> </LABEL>
                            </TD>
                            <TD><TEXTAREA cols="63" name="TextArea1" rows="30" style="BACKGROUND-COLOR: white; HEIGHT: 165px; WIDTH: 590px"
                                    ID="Textarea1"></TEXTAREA>
                                <P></P>
                                <P><BR>
                                </P>
                            </TD>
                        </TR>
                    </TABLE>
                    <INPUT name="B1" type="submit" value="Send" ID="Submit1"></P>
            </form>
            <%end if %>
        </body>
    </html>
  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