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:
- Create a folder under \Inetpub\wwwroot named Sendmailsample.
- Open Notepad.
- 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>
- Save the file as Sendmail.asp in the Sendmailsample folder that you created above.
- Open Internet Service Manager.
- In the properties for the Sendmailsample folder, set the security properties to Digest Authentication for Windows Domain Servers and Integrated Windows Authentication.
- Load the page in IIS.
- Fill in the form, and then click Send.