CDOSYS is a built-in component in ASP used to send e-mails. CDOSYS was designed to replace Microsoft’s older CDONTS component, which was phased out in Windows 2003.
The first thing you need to do is create a /FormPage.asp page with the code below:
<form name="YourFormName" method="Post" action="confirmation.asp">
Email: <input type="text" name="Email" size="50"><br>
First Name: <input type="text" name="FirstName" size="50"><br>
Last Name: <input type="text" name="LastName" size="50"><br>
Subject: <input type="text" name="Subject" size="50"></td><br>
Comments: <textarea name="Comments"></textarea><br>
<input type="submit" name="Submit" value="Submit Form">
</form>
Next, we create a /Confirmation.asp page with our CDOSYS code as seen below:
<%
DIM strEmail, strFirstName, strLastName, strComments
strEmail = request.form("Email")
strFirstName = request.form("FirstName")
strLastName = request.form("LastName")
strComments = request.form("Comments")
Set myMail=CreateObject("CDO.Message")
myMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing")=2
'Name or IP of remote SMTP server
myMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver")="mail.YourDomain.com"
'SMTP Username and Password
myMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusername") = "YourUsername"
myMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "YourPassword"
myMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
myMail.Configuration.Fields.Update
myMail.From = strEmail
myMail.To = "YourEmail@YourDomain.com"
myMail.Bcc = "YourEmail@YourDomain.com"
myMail.Cc = "YourEmail@YourDomain.com"
myMail.Subject = "CDOSYS Email"
myMail.TextBody = strComments
'Catch any errors.
On Error Resume Next
myMail.Send
If (Err <> 0) Then
Response.Write "There was an error sending the email: " & Err.Description
End If
Set myMail = nothing
%>
<p>
<%
strFirstName = Request.Form("FirstName")
Response.Write strFirstName
%>,</p>
<p>Thank you for emailing me.</p>
Now you have a form that sends a text email and displays a customized message for your user. If you would like to send an email in HTML format, you can simply replace “myMail.TextBody” with “myMail.HTMLBody.
Enjoy!