Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

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


View products that this article applies to.

This article was previously published under Q248687

↑ Back to the top


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.

↑ Back to the top


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.

↑ Back to the top


Keywords: KB248687, kbmsg, kbhowto

↑ Back to the top

Article Info
Article ID : 248687
Revision : 9
Created on : 4/4/2006
Published on : 4/4/2006
Exists online : False
Views : 447