Sending Mail Using CDOEX and Exchange Server 2007
Topic Last Modified: 2009-07-27
Example
VBScript
'Send Mail using CDOEx and Exchange Server
'
'1) Create a folder named "test" under inetpub/wwwroot.
'2) Save this file in that folder as NewMail.asp
'3) Make the changes to the file i.e. Change the iMsg.From line to reflect your mailbox.
'4) Save the file.
'5) open internet service manager and browse to the "test" folder
'6) right-click and go to properties
'7) go to the "Directory Security" tab.
'8) Click on "Edit" button next to the "handshake" icon
'9) Uncheck "Anonymous Access"
'10) check the "Digest Authentication" and "Integrated windows authentication" boxes
'11) click ok
'12) click ok
'13) load the asp in your browser.
'14) Fill in the fields on the html form
'15) click "submit" to send mail.
<%@ Language=VBScript %>
<%
submit = Request.Form.Item("B1")
if submit = "Send" then
Dim iMsg
'Create the message object
Set iMsg = CreateObject("CDO.Message")
Dim iConf
'Create the configuration object
Set iConf = CreateObject("CDO.Configuration")
Dim Flds
'Set the fields of the configuration object to send using exchange server
Set Flds = iConf.Fields
Flds( "https://schemas.microsoft.com/cdo/configuration/sendusing") = 3
Flds.Update
'Set the message to,from,subject,body properties.
Set iMsg.Configuration = iConf
iMsg.To = Request.Form.Item("Text1")
iMsg.From = "someone@someplace.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 >
<% if submit = "Send" then %>
Mail Sent
<%else%>
<form name="mnFrm" method="post" action="NewMail.asp">
<P>
<base target="_top">
<TABLE >
<tr>
<TD> To </TD>
<TD><INPUT name=Text1 size=58 style="HEIGHT: 22px; WIDTH: 500px"></TD></TR>
<TR>
<TD><LABEL> Subject </LABEL></TD>
<TD><INPUT border=0 name=Text3 size=58
style="HEIGHT: 22px; WIDTH: 500px"></TD></TR>
<TR>
<TD vAlign=top><LABEL> Body </LABEL></TD>
<TD><TEXTAREA cols=63 name=TextArea1 rows=30 style="BACKGROUND-COLOR: white; HEIGHT: 165px; WIDTH: 590px"></TEXTAREA>
<P></P>
<P><BR></P></TD></TR></TABLE><INPUT name=B1 type=submit value="Send"></P>
</form>
<%end if %>
</body>
</html>