//  home   //  advanced search   //  news   //  categories   //  sql build chart   //  downloads   //  statistics
 ASP FAQ 
Home
ASP FAQ Tutorials

   8000XXXX Errors
   Alerts
   ASP.NET 2.0
   Classic ASP 1.0
      COM / ActiveX Components
      Forms
      General Topics
      Date/Time Routines
      Email Scripts & Info
      Files/Directories & FSO
   Databases
   General Concepts
   Search Engine Optimization (SEO)

Contact Us
Site Map

Search

Web
aspfaq.com
tutorials.aspfaq.com
classicasp.aspfaq.com

ASP FAQ Tutorials :: Classic ASP 1.0 :: Email Scripts & Info :: How do I send e-mail with CDO?


How do I send e-mail with CDO?

To send an e-mail with Active Server Pages requires some kind of component. There are many third party components available (see bottom of page), but one of the most readily available is the free Microsoft mail component CDO, which ships with Windows 2000, Windows XP, and Windows Server 2003. 
 
We removed the code snippets using CDONTS, because it has many problems and has been deprecated. We highly recommend you use CDO.Message, and if you have existing CDONTS code, that you convert it to CDO.Message now, rather than waiting until you absolutely have to. If you try to run CDONTS.NewMail on Windows XP or Windows Server 2003, you might get one of the following errors: 
 
Invalid class string 
' or 
ActiveX component can't create object: 'CDONTS.NewMail' 
' or 
The "SendUsing" configuration value is invalid.
 
This is because CDONTS has been deprecated and no longer ships with Windows (see KB #810702 for more information). To deal with this, you should start using the new code style in all of your applications: 
 
<% 
    sch = "http://schemas.microsoft.com/cdo/configuration/" 
 
    Set cdoConfig = CreateObject("CDO.Configuration") 
 
    With cdoConfig.Fields 
        .Item(sch & "sendusing") = 2 ' cdoSendUsingPort 
        .Item(sch & "smtpserver") = "<enter_mail.server_here>" 
        .update 
    End With 
 
    Set cdoMessage = CreateObject("CDO.Message") 
 
    With cdoMessage 
        Set .Configuration = cdoConfig 
        .From = "from@me.com" 
        .To = "to@me.com" 
        .Subject = "Sample CDO Message" 
        .TextBody = "This is a test for CDO.message" 
        .Send 
    End With 
 
    Set cdoMessage = Nothing 
    Set cdoConfig = Nothing 
%>
 
To see the differences between CDONTS and CDO, see KB #177850. Also, see Article #2308 for external information on configuring/using CDO. 
 
You can handle it this way also -- thanks to Siegfried Weber for the advice -- including the CDO type library so you don't have to use the schema URL/namespace, and this also allows you to use the named CDO constants: 
 
<!-- 
    METADATA 
    TYPE="typelib" 
    UUID="CD000000-8B95-11D1-82DB-00C04FB1625D"  
    NAME="CDO for Windows 2000 Library" 
-->  
<%  
    Set cdoConfig = CreateObject("CDO.Configuration")  
 
    With cdoConfig.Fields  
        .Item(cdoSendUsingMethod) = cdoSendUsingPort  
        .Item(cdoSMTPServer) = "<enter_mail.server_here>"  
        .Update  
    End With 
 
    Set cdoMessage = CreateObject("CDO.Message")  
 
    With cdoMessage 
        Set .Configuration = cdoConfig 
        .From = "from@me.com" 
        .To = "to@me.com" 
        .Subject = "Sample CDO Message" 
        .TextBody = "This is a test for CDO.message" 
        .Send 
    End With 
 
    Set cdoMessage = Nothing  
    Set cdoConfig = Nothing  
%>
 
Or you can use the workaround of copying cdonts.dll from a Windows 2000 machine and regsvr32'ing it on the XP machine. I have not tested this method, so try it at your own risk. If it works, it may — at least in the short term — be the better solution. But you should plan to migrate your code eventually, because hosts running Windows 2003 are unlikely to be willing to register obsolete DLLs. 
 
If you switch to the new code technique, the advantage is that it works on Windows 2000... so you can migrate your code gradually. There is a comprehensive article here -- describing all of the methods and properties, and showing a few code samples: 
 
    http://msdn.microsoft.com/library/en-us/... 
 
And here is a good starting point: 
 
    http://msdn.microsoft.com/library/en-us/... 
 
Sending an Attachment 
 
To add an attachment to a message, you can simply add the .AddAttachment method to your existing code: 
 
    ' ... 
    With cdoMessage 
        Set .Configuration = cdoConfig 
        .From = "from@me.com" 
        .To = "to@me.com" 
        .Subject = "Sample CDO Message" 
        .TextBody = "This is a test for CDO.message" 
        .AddAttachment "c:\boot.ini" 
        .Send 
    End With 
    ' ...
 
Remember that this attaches files that are on the file system of the *SERVER* — if you want to attach files from the client, you need to have the client upload them to the server first; please see
Article #2189
 
Problems 
 
If you are having difficulties with CDO, see the following reference: 
 
   
http://msdn.microsoft.com/library/en-us/... 
 
If you get "Permission Denied" errors, try switching "run in separate memory space" off and on again for the web site / application (this setting is located within Internet Services Manager). Also see these KB articles; KB #286301, KB #228465, and KB #197619
 
If you get "The system cannot find the path specified" errors, you may need to (re)install the SMTP service. For details, see KB #235681
 
If you get "8004020E" or "80040211" errors, and you are using a remote SMTP server, make sure that you can establish a telnet session on the SMTP server from the web server, that the SMTP server is configured to allow SMTP relay, and that it doesn't require outgoing SMTP authentication. If it requires outgoing authentication, you may need to use the commercial version of
ASPEmail, or another component that supports outgoing SMTP authentication. You can send e-mail to an SMTP server requiring outgoing authentication with CDO using the following code: 
 
<!-- 
    METADATA 
    TYPE="typelib" 
    UUID="CD000000-8B95-11D1-82DB-00C04FB1625D"  
    NAME="CDO for Windows 2000 Library" 
-->  
<%  
    Set cdoConfig = CreateObject("CDO.Configuration")  
 
    With cdoConfig.Fields  
        .Item(cdoSendUsingMethod) = cdoSendUsingPort  
        .Item(cdoSMTPServer) = "<enter_mail.server_here>"  
        .Item(cdoSMTPAuthenticate) = 1  
        .Item(cdoSendUsername) = "<enter_username_here>"  
        .Item(cdoSendPassword) = "<enter_password_here>"  
        .Update  
    End With 
 
    Set cdoMessage = CreateObject("CDO.Message")  
 
    With cdoMessage 
        Set .Configuration = cdoConfig 
        .From = "from@me.com" 
        .To = "to@me.com" 
        .Subject = "Sample CDO Message" 
        .TextBody = "This is a test for CDO.message" 
        .Send 
    End With 
 
    Set cdoMessage = Nothing  
    Set cdoConfig = Nothing  
%>
 
You might also check that your SMTP server isn't restricted to a certain set of domain names in the recipients or senders lists (depending on what your SMTP software supports) and that the correct ports are open if there is a firewall or router sitting between your web server and the mail server. 
 
If you get "80040222" or "80040220" errors, see Article #2418. Also if you are using local pickup, try adding an explicit pickup folder that IUSR_MachineName has access to: 
 
With cdoConfig.Fields  
    ' ... 
    .Item(cdoSMTPServerPickupDirectory) = someEligibleFolder 
    ' ... 
End With
 
Last resort... 
 
If CDO continues to frustrate you, check out Article #2119 for a thorough list of alternative SMTP components. Your web host almost certainly supports at least one of them. If they don't, they should. 
 
Another alternative, if you're using SQL Server, is to send the mail from within the database. Your ASP page can pass parameters to a stored procedure that sends the mail without having to use CDO or a custom COM object on your web server. See Article #2403 for a quick tutorial.

Related Articles

Can I get CDO messages to return a read receipt?
Can I use a remote SMTP server with CDONTS.NewMail?
How do I alter the priority / importance of an e-mail message?
How do I prevent my links from wrapping in an e-mail?
How do I put carriage returns into an e-mail?
How do I send e-mail from ASP?
How do I send e-mail from SQL Server?
How do I send e-mail in HTML format?
How do I validate an e-mail address?
Should I use form action=mailto: to mail the results of a form?
Where can I get more details about configuring / using CDO?
Why can't ASP handle 80,000 e-mails?
Why do CDONTS messages end up in the badmail folder?
Why do I get 8000900F errors?
Why do I get 80040108 errors?
Why do I get 8004020A errors?
Why do I get 80090020 errors?
Why do I get C00402CE / C00402C7 errors?
Why does CDO.Message give 800C000D errors?
Why does CDO.Message give me 8004020F errors?
Why does CDO.Message give me 80040213 errors?
Why does CDO.Message give me 80040222 errors?
Why does my CDONTS mail hang out in the queue or pickup folders?
Why is e-mail to certain domains being rejected?

 

 


Created: 7/9/2000 | Last Updated: 10/26/2005 | broken links | helpful | not helpful | statistics
© Copyright 2006, UBR, Inc. All Rights Reserved. (330)

 

Copyright 1999-2006, All rights reserved.
Finding content
Finding content.  An error has occured...