Before you write one lick of code, think about these things :
Just because people have email accounts, that doesn't mean that you should have free reign and send them all sorts of nonsense. If you are going to ask for their email address, do not abuse it. Its akin to asking someone for their telephone number, or home address. What if everytime you told someone your phone number, you got calls from people you didn't know trying to tell you how they can get you a college diploma for $25? Not only that, you get these phone calls up to 80 times a day? I understand that some people have websites up there that are running on whats called click-thru or reference dollars. If you have such a partnership, please have the decency to add a little footer telling people on how to opt out. And I don't mean that little footnote written in font size -1000 that would take a guy with a 32 inch plasma screen four microscopes to read. Well, enough about that. I trust we are all sensible netizens. You guys know what I'm talking about.
Now, on to the good stuff: how do I send mail from my webpage? If you are on any Microsoft platform, and you are scratching your head looking for a way to send email via ASP, let me introduce you to your new best friend.
Collaboration Data Objects or CDO for short
What is CDO?
Simply put, CDO is a framework, a bridge if you will, that allows access to an email server. Using CDO, you can create and send messages using the SMTP (IIS 4.0) or through MAPI (MS Exchange Server) more on this later. But first, three lines of code to send email!
<% Set mailHook = Server.CreateObject("CDONTS.Newmail") mailHook.Send "firstname.lastname@example.org","email@example.com","Subject","Body" Set mailHook = nothing%>
That's it! --Instant email sending. But I know what you are thinking, "what the heck is CDONTS? He was just talking about CDO earlier." Fear not, read on.
Two Versions of CDO
There are two versions of CDO available from Microsoft. CDO 1.2 and CDO for NTS (NT Server). CDONTS is a trimmed down version of CDO 1.2 and is included with IIS 4 and 5. CDO 1.2 is the full blown version, and it is bundled with Microsoft Exchange Server. I believe that Microsoft has come out with newer versions of CDO for the 2K line of products, providing more functionality (or so they say), but more than likely, more bugs. So, I'd stick with 1.2 for now...till the first few rounds of Service Packs are out at least. What is the difference between the two? Nothing too serious on the outside, but the main way they differ is in their communication protocols. CDO uses the Microsoft Messaging Application Program Interface (MAPI) and CDONTS uses Simple Mail Transfer Protocol (SMTP). Below is a simple table of features that are supported on each.
|Table of Comparison|
|Accessible with ASP?||Yes||Yes|
|Requires authenticated user login?||Yes||No|
|Supports remote access?||Yes||No|
|Supports multiple servers?||Yes||No|
|Provides calendars, filters, sorting?||Yes||No|
|Provides for writing to Message Object?||Yes||Yes|
|Provides for reading from Message Object?||Yes||No|
|Renders messages in HTML for browser veiwing?||Yes||No|
|Uses HTML/MHTML for transmission of rich text and graphics?||No||Yes|
What was the point of all this you may ask? Well, simply put, ASP provides for easy integration of email capabilities into existing solutions through the use of Collaboration Data Objects. Think of it this way: you compile an ActiveX DLL that stores all your emailing code, with of course code that will filter, sort, etc. your mailing lists, and you have a powerful and fast (compiled DLLs are always faster than inline ASP) way of implementing email. So, the next time a user hobbles on to your site, you can provide customized content, interesting emails (err...), flyers that have your site updates included (hmm...), your schedule and when you are free (*scratches head*)...wait, why did I write this?! This is the perfect weapon for all those that want to mailbomb people! Come to think of it...maybe I should delete this thing...ah heck, I'll just send an email to have it done ;)
On a personal note, I was wondering if anyone had any ideas on how to implement a similar solution ... using PHP? [This would make a great followup article --ed]
As always, I look forward to your replies, complaints, etc.