iNET Interactive - Online Advertising Agency
          
   Home    Authors    About    Login    Contact Us
   Search:   
Advanced Search     
  Articles

  ASP (26)
  ASP.NET (19)
  C and C++ (4)
  CFML (2)
  CGI and Perl (16)
  Flash (2)
  Java (7)
  JavaScript (28)
  PHP (92)
  MySQL (13)
  MSSQL (3)
  HTML (34)
  SEO (9)
  Visual Basic (12)
  CSS (13)
  SSI (5)
  XML (12)
  C# (14)

  Developer News

May 11, 2008
Improving accessibility for motor impaired users
WebDevTips UK
 
May 11, 2008
10 ways to orientate users on your site
WebDevTips UK
 
May 11, 2008
Web Design Clinic - Rros restoration camp 2006
About
 
May 10, 2008
The Moods of Facebook
About
 
May 9, 2008
CSS 1 properties are a great start
About
 
May 9, 2008
Reader Question: How do you get fancy fonts?
About
 
Courtesy of moreover.com
 
Want to receive new articles via e-mail? Click here!
/Home /ASP

CDOSYS, the new CDONTs! 

  Views:    17042
  Votes:    5
by Drew Gauderman 1/24/06 Rating: 

Synopsis:

In Windows 2003 and above CDONTS is no longer supported and has been replaced with CDOSYS.
Pages: 
The Article

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") = 25
Next is the CDO port.

'CDO Port
objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
Next 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") = 60
Update 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

Pages: 

Similar/related articles:


 
  Sponsors