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:
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:
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:
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:
And here is a good starting point:
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.
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:
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:
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 ArticlesCan 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?