fordwebs.com - website development and maintenance

fordwebs.com CDOSYS 64-bit Windows Server 2008 tutorial

This tutorial will show you how to use CDOSYS on 64-bit Windows Server 2008 to send an email from a form page.

The first thing that you need to do is to create a 32-bit Application Pool. To do this you need to open the Internet Information Services (IIS) Manager. Click Start > Administrative Tools > Internet Information Services (IIS) Manager

Open IIS Manager

When the Internet Information Services (IIS) Manager opens expand the server and click Application Pools. Then click Add Application Pool in the Actions Panel on the right.

Add Application Pool

In the Add Application Pool window give the new Application Pool a Name and click OK.

Application Pool Name

You then need to open the Advanced Settings for the Application Pool that you just created. Do this by clicking on the Application Pool in the center Application Pools panel and then click Advanced Settings... in the right Actions panel.

Selecting Advanced Settings

Change the Enable 32-Bit Applications to True and the Load User Profile to False and click OK.

Advanced Settings Window

You will now convert the folder in the website to an application that will use the 32-bit application pool you created. Do this by right-clicking on the appropriate folder and select Convert to Application.

Convert To Application

Select the 32-bit Application Pool you created and click OK.

Select Application Pool

You now need to download and install the Microsoft Exchange Server MAPI Client and Collaboration Data Objects 1.2.1. Get it here.

After installing the Microsoft Exchange Server MAPI Client and Collaboration Data Objects 1.2.1 you will need to register the cdosys.dll. Do this by typing the following in a Command Prompt:

regsvr32 "C:\Windows\System32\cdosys.dll"

You are now ready to use CDOSYS to send an email from a web page.

Create a form page with the following and save it as formpage.asp:

<form id="myForm" name="myForm" method="post" action="responsepage.asp">

<p>First Name: <input name="FirstName" type="text" id="FirstName" size="30" /></p>

<p>Last Name: <input name="LastName" type="text" id="LastName" size="30" /></p>

<p>Email: <input name="Email" type="text" id="Email" size="30" /></p>

<p>Comments: <textarea name="Comments" id="Comments" cols="35" rows="5"></textarea></p>

<p><input name="doIt" type="hidden" id="doIt" value="true" />

<input type="submit" name="Submit" id="Submit" value="Submit" /></p>

</form>

Create a response page with the following and save it as responsepage.asp:

<%

' If the form page is submitted

If Request.Form("doIt") = "true" Then

' Dim the variable

Dim ObjSendMail

' Create the message object

Set ObjSendMail = CreateObject("CDO.Message")

' This section provides the configuration information for the remote SMTP server.

ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 'Send the message using the network (SMTP over the network).

ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") ="mail.yoursite.com"

ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25

ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = False 'Use SSL for the connection (True or False)

ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60

' If your server does not require outgoing authentication comment the lines below.

ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1 'basic (clear-text) authentication

ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusername") ="YourUserName"

ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendpassword") ="YourPassword"

ObjSendMail.Configuration.Fields.Update

' End remote SMTP server configuration section

'Dim the variables

Dim strFirstName, strLastName, strEmail, strComments, strSubject, strBody

' Set the strings as the form elements

strFirstName = Request.Form("FirstName")

strLastName = Request.Form("LastName")

strEmail = Request.Form("Email")

strComments = Request.Form("Comments")

' Set the from email

strFrom = "webmaster@yoursite.com"

' Set the CC email address

strCc = "someone@yoursite.com"

' Set the Subject Line

strSubject = "Example Online Form Submission"

' Set the body of the message

strBody = "The following info has been submitted" & vbCrLf & vbCrLf &_

"First Name: " & Request.Form("FirstName") & vbCrLf &_

"Last Name: " & Request.Form("LastName") & vbCrLf &_

"Email: " & Request.Form("Email") & vbCrLf &_

"Comments: " & Request.Form("Comments") & vbCrLf & vbCrLf &_

"Someone will contact you as soon as possible."

' Set the parameters

ObjSendMail.From = strFrom

ObjSendMail.To = strEmail

ObjSendMail.Cc = strCc

ObjSendMail.Subject = strSubject

' we are sending a text email.. simply switch the comments around to send an html email instead

'ObjSendMail.HTMLBody = strBody

ObjSendMail.TextBody = strBody

' Send the email

ObjSendMail.Send

' Set the object to nothing

Set ObjSendMail = Nothing

End If

%>

This will send the email to the submitter and send a carbon copy to you. Now let's add some more code to display the results on the page.

<h1>Thank you!</h1>

<p>You submitted the following information:</p>

<p>First Name: <%= strFirstName %><br />

Last Name: <%= strLastName %><br />

Email: <%= strEmail %><br />

Comments: <%= strComments %></p>

<p>Someone will contact you as soon as possible.</p>

That is all there is too it!

 

© Copyright 2008 Fordwebs, LLC All Rights Reserved.

Valid XHTML 1.0 Transitional   Valid CSS