asp tutorials, asp.net tutorials, sample code, and Microsoft news from 15Seconds
Data Access  |   Troubleshooting  |   Security  |   Performance  |   ADSI  |   Upload  |   Email  |   Control Building  |   Component Building  |   Forms  |   XML  |   Web Services  |   ASP.NET  |   .NET Features  |   .NET 2.0  |   App Development  |   App Architecture  |   IIS  |   Wireless
 
Pioneering Active Server
 Power Search





Active News
15 Seconds Weekly Newsletter
• Complete Coverage
• Site Updates
• Upcoming Features

More Free Newsletters
Reference
News
Articles
Archive
Writers
Code Samples
Components
Tools
FAQ
Feedback
Books
Links
DL Archives
Community
Messageboard
List Servers
Mailing List
WebHosts
Consultants
Tech Jobs
15 Seconds
Home
Site Map
Press
Legal
Privacy Policy
internet.commerce














internet.com
IT
Developer
Internet News
Small Business
Personal Technology
International

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers

HardwareCentral
Compare products, prices, and stores at Hardware Central!

Collaboration Data Object and IIS 4.0
By Jon Whiting
Rating: 3.9 out of 5
Rate this article


  • email this article to a colleague
  • suggest an article

    Introduction

    Collaboration Data Objects (CDO) is a COM library designed to send mail through SMTP (Simple Mail Transfer Protocol) or Microsoft Exchange. If you install the SMTP server that comes with Microsoft Option Pack 4, you can send mail from an Active Server page using CDO. Because CDO comes with Microsoft Option Pack 4, CDO is free.

    Sending Mail

    It only requires three lines of code to send e-mail from an Active Server page using CDO, as shown in Example 1.

    Example 1

    
    Set objMail = Server.CreateObject("CDONTS.NewMail")
    objMail.Send "fromuser@domain.com","touser@domain.com","Test Mail",
    	"This is a test mail using CDO",0
    Set objMail = nothing
    
    
    When you create the Newmail object, it actually creates a CDO Session, and logs into the SMTP server that is installed on the same system as the Web Server. You must install Microsoft’s SMTP server that comes with NT Option Pack 4. There is no way to change the SMTP server that the CDO object uses.

    After the e-mail is sent, the Newmail object becomes invalid, so you need to make sure to set the object to Nothing. To send another piece of e-mail, you must recreate the Newmail object.

    There is no SMTP error checking done in the Newmail object. The object submits the e-mail to the SMTP server where it is sent or rejected. The script running the object does not get an error code from the object since the process takes place on the SMTP server. Any delivery errors in the e-mail will be forwarded from the SMTP server to the From (that is, the sender’s) e-mail address.

    There are two ways to send e-mail using the Newmail object. The first, demonstrated in Example 1, uses the Send method, passing parameters with it. The second way is to separate the parameters out, and set each of them individually. Example 2 demonstrates the setting of individual parameters:

    Example 2

    
    
    Set objMail = Server.CreateObject("CDONTS.NewMail")
    objMail.From="user@domain.com"
    objMail.To="user@domain.com"
    objMail.Subject="Test Mail"
    objMail.Body="This is a test mail using CDO"
    objMail.importance=0
    objMail.Send
    Set objMail = nothing
    
    
    
    If you want to change the priority on the e-mail, set the importance attribute to one of the settings listed below:
    0Low
    1Normal
    2High
    In example 2, the importance was set to low.

    Attaching a File

    You can use the Newmail Object to attach a file to the e-mail message. To attach a file, you call the AttachFile method on the Newmail object. You need to specify the file to attach and, if you want to rename the file, a new name for the file.

    Example 3: Attaching a File

    
    
    Set objMail = Server.CreateObject("CDONTS.NewMail")
    objMail.attachFile("\\server\share\file.txt","test.txt")
    objMail.Send("user@Domain.com","user@Domain.com","Test Mail",
    	"This is a test mail using CDO",0)
    Set objMail = nothing
    
    
    

    Sending Mail from a Form

    You can use the Newmail object to send the contents of a form to an e-mail address.

    Example 4: Using a Form to send mail

    
    
    <html>
    <body>
    <%
    If request("Button")="Send Mail" then
    Set objMail = Server.CreateObject("CDONTS.NewMail")
    For each sRequest in Request.Form
    	response.write sRequest
    	Select Case sRequest
    	Case "From"
    		objMail.From=request(sRequest)
    	Case else
    		sBody=sBody & sRequest & " - " & request(sRequest) & chr(13)
    	End select
    Next
    response.write sBody
    objMail.Body=sBody
    objMail.To="user@domain.com"
    objMail.Subject="Results from a form"
    objMail.Send
    set objMail = nothing
    response.write "Mail Sent"
    else
    %>
    	<form action="FormMail.asp" method="POST" name="CDOMail">
    	Name: <input type="text" size="20" name="Name"><br>
    	Address:<input type="text" size="20" name="Address"><br>
    	City: <input type="text" size="20" name="City"><br>
    	State: <input type="text" size="20" name="State"><br>
    	Zip: <input type="text" size="20" name="Zip"><br>
      	Phone: <input type="text" size="20" name="Phone"><br>
      	Email: <input type="text" size="20" name="From"><br>
      	<input type="submit" name="Button" value="Send Mail">
    	</form>
    <%
    End if
    %>
    </body>
    </html>
    
    
    

    Sending Mail to a list

    You could very easily set up a mailing list. Display a form on your web site that collects e-mail addresses and saves them to a database. Use that database and the code in Example 5 to send messages to the list of people. If the SMTP server cannot send all of the e-mail as fast as you create it, the server will save the e-mail in a directory and then catch up as it has time.

    Example 5: Sending to a list

    
    
    Set Conn = Server.CreateObject("ADODB.Connection")
    sConnect = "dsn=MailingListDB"
    Conn.Open sConnect
    Set rsEmails=Conn.Execute("Select EmailAddress From Users")
    Do While not rsEmails.eof
    	Set objMail = Server.CreateObject("CDONTS.NewMail")
    	objMail.From="user@Domain.com"
    	objMail.To=rsEmails("EmailAddress")
    	objMail.Subject="Test Mail"
    	objMail.Body="This is a test mail using CDO"
    	objMail.importance=0
    	objMail.Send
    	Set objMail = nothing
    	rsEmails.movenext
    loop
    set rsEmails = nothing
    Conn.close
    Set Conn = nothing
    
    
    
    You will have to change the DSN and SELECT statements to match your database setup. Also, if you have a big mailing list you will have to increase the script timeout value so the Active Server page has enough time to send all the people in the mailing list without timing out. Here is how to set the timeout for 300 seconds:

    
    
    Server.ScriptTimeout = 300
    
    
    

  • Rate This Article
    Not HelpfulMost Helpful
    1 2 3 4 5
    Supporting Products/Tools
    AspEmail
    Free SMTP component that supports multiple file attachments, unlimited recipients, CC's, BCC's and REPLY-TO's. Sends messages as plain text or in the HTML format. Premium features include message queuing and deferred processing for high mail volumes. When used with AspEncrypt, generates S/MIME-enabled secure mail.
    [Top]
    AspMail
    AspMail supports multiple file attachments (MIME and UUE), US ASCII and ISO-8859-1 character sets, 8bit subject lines, custom message content headers, custom message headers, MS Exchange priority headers, PGP and more.
    [Top]
    DevMailer 1.0
    DevMailer adds SMTP email sending abilities to ASP or Perl programs. Features include: attachments, failsafe queueing, redundant servers, standard message file support, and advanced activity logging. Also verify email addresses and send multiple messages on a single connection.
    [Top]
    JangoMail
    JangoMail, located at JangoMail.com, is a web-based service that sends mass e-mails by connecting to data from your SQL Server or ODBC compliant database. Unlike traditional ASP e-mail components, the JangoMail service can also handle unsubscribes and bounces automatically and synchronize these with your original web database. The only setup that is required is the placement of one ASP file on your web server. Other features include message open tracking and click tracking.
    [Top]
    JMail
    Send Email directly from you web page via your webserver. jMail will not start up any annoying email clients, just smoothly send the mail via the mailserver. Implement it with easy ASP code.
    [Top]
    Mail for .NET
    Mail for .NET is the first product for the NetToolworks.NET framework. Together they provide methods that send, receive, compose, edit, encode and decode e-mail messages. SMTP, POP, complex MIME messages, HTML messages, and file/memory streaming are also supported.
    [Top]
    OCXMail
    A single component that is limited in scope to five methods. The OCXMail ASP component allows you to send mail using the standard SMTP protocol from any program that can use ActiveX/OLE components.
    [Top]
    ocxQMail
    The ocxQmail ASP component allows you to send mail using the standard SMTP protocol from any program that can use ActiveX/OLE components. ocxQmail queues up messages for batch delivery by a companion NT Service at intervals you specify in the Administration Windows GUI. Your ASP pages do not have to wait for the mail message to be physically sent before continuing.
    [Top]
    RobustPop3
    RobustPOP3 component allows you to retrieve mail using POP3 protocol. Features include: Retrieve Messages Multiple File Attachments, File Attachments support MIME and UUEncode.
    [Top]
    SA-SmtpMail
    A full-featured SMTP e-mail client component that allows developers to send e-mail from any client. This award-winning control offers significantly better performance than other popular SMTP components. SoftArtisans SMTPmail is written in high-performance C++ and supports all threading models, file attachments and multiple encoding schemes. New features in version 2.0 include login authentication and mass mail. The new version also supports PGP encryption.
    [Top]
    Other Articles
    Sep 29, 2005 - Migrating to a Load Balanced IIS 6 Environment
    Migration to IIS 6 can present itself as a daunting challenge. Depending on your existing hosting configuration, the process can number in hours, days, or even weeks. Careful planning and research is integral to achieve a successful migration.
    [Read This Article]  [Top]
    Apr 18, 2003 - IIS 6.0: Lessons in Trustworthy Computing
    Microsoft's Trustworthy Computing initiative significantly changed the way in which Microsoft builds and designs software. In this article, Jeff Gonzalez explores some of the new options and architecture in Internet Information Services 6.0.
    [Read This Article]  [Top]
    Mar 25, 2002 - Moving IIS To A Different Server - Part 2
    Brien Posey evaluates two additional methods for migrating a Web server and it settings, backup/restore and ghosting.
    [Read This Article]  [Top]
    Feb 27, 2002 - Moving Your IIS Server to a New Server - Part 1
    Upgrading your server? Brien Posey takes a look at the process and pitfalls of migrating IIS to a completely different server.
    [Read This Article]  [Top]
    Jan 23, 2002 - Troubleshooting IIS Access Problems
    Spending countless hours developing a Web site only to discover that no one can access it is frustrating. This article guides you through the process of troubleshooting Web-site access problems.
    [Read This Article]  [Top]
    Jan 18, 2002 - Running IIS on Windows XP Home Edition?
    Members of the 15Seconds discussion list may have found a way to run IIS on Windows XP Home Edition, so developers can run ASP pages. Attempt at your own risk!
    [Read This Article]  [Top]
    Dec 27, 2001 - Working With IIS Packet Filtering
    Brien Posey discusses IP packet filtering and other ways in which to control access through IIS.
    [Read This Article]  [Top]
    Oct 30, 2001 - Protecting Your IIS Server and Web Application
    Internet viruses such as Code Red and Nimbda have brought down numerous IIS Web servers recently. Fortify and defend your system with this comprehensive strategy authored by 30-year industry veteran, Andrew Novick.
    [Read This Article]  [Top]
    Oct 16, 2001 - Implementing an E-mail Content Filter Using CDO
    Stop SPAM from sliding through your e-mail system. George Walker shows how to create an e-mail content filter for the Windows 2000 SMTP service using Microsoft Collaboration Data Objects.
    [Read This Article]  [Top]
    Feb 10, 2000 - Creating Dynamic JavaScript with ASP and Databases
    Travis Giggy demonstrates how to put ASP tags inside of JavaScript blocks so developers can fit large amounts of data into one form on a single page. He offers an overview of things that can be done with dynamic JavaScript with ASP and data queries.
    [Read This Article]  [Top]
    Mailing List
    Want to receive email when the next article is published? Just Click Here to sign up.

    Support the Active Server Industry



    JupiterOnlineMedia

    internet.comearthweb.comDevx.commediabistro.comGraphics.com

    Search:

    Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

    Jupitermedia Corporate Info


    Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

    Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers