If you are reading this page then I shall assume that you already know a little bit about ASP and running ASP scripts.
This tutorial is just a code sample of CDOSYS. Im not going to show you how to setup a form and javascript to send an email. Instead I'm going to concentrate on the actual methods and properties the CDOSYS object uses to format and then send the e-mail.
Now, back to the topic at hand. If you currently use CDONTS for sending email, the time may have come to bury the dead and move on. Microsoft introduced CDONTS with IIS4, allowing programmers to easily send email from ASP without purchasing and installing 3rd-party components. But, like any evolving technology, a new version has taken center stage. CDOSYS is Microsoft's new and improved interface for SMTP email which was introduced in Windows 2000.
First we need to create the variables that we are going to be using in this script.
<%
'Dimension variables
Dim objCDOSYSCon
Next we need to create an instance of the 'CDOSYS NewMail' object on the server.
'Create the e-mail server object
Set objCDOSYSMail = Server.CreateObject("CDO.Message")
Set objCDOSYSCon = Server.CreateObject ("CDO.Configuration")Now that the object is created we need to set the mail server settings.
First we are going to enter the SMTP server. The SMTP server is usly mail.yoursite.com (replace yoursite.com with the url of you site). If you dont enter the right SMTP server name or you dont have one the email will fail. 'Set and update fields properties
'Out going SMTP server
objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "mail.yoursite.com"Next we are going to enter the Port of the mail server. Port 25 is the default port. Check with your server to make sure its not something else.
'SMTP port
objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25Next is the CDO port.
'CDO Port
objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2Next is setting the Timeout setting. This is used to set a timeout if the script doesnt continue.
'Timeout
objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60Update the settings.
'Update settings
objCDOSYSCon.Fields.Update
'Update the CDOSYS Configuration
Set objCDOSYSMail.Configuration = objCDOSYSCon
Now we are going to enter who the email is from. If you leave this property out or do not have a properly format e-mail address the e-mail will fail.
'Who the e-mail is from
objCDOSYSMail.From = "you @ yoursite.com"
Now we are going to enter the address of the person going to receive the email.
'Who the e-mail is sent to
objCDOSYSMail.To = "someone @ theirsite.com"
Now we are going to enter the Subject.
'The subject of the e-mail
objCDOSYSMail.Subject = "Subject goes here"
And now we are going to enter the message of the email.
'Set the e-mail body format (HTMLBody=HTML TextBody=Plain)
objCDOSYSMail.HTMLBody = "html enhanced email message goes here"
Send the email and
Close the connections.'Send the e-mail
objCDOSYSMail.Send
'Close the server mail object
Set objCDOSYSMail = Nothing
Set objCDOSYSCon = Nothing
%>
Red = things you need to change for your site
Now just copy the following code into an asp page and change the things in red to match your site. Dont forget to change the 'outing going smtp server'!!
If you enjoy this article feel free to visit my website at: http://www.iportalx.net