 |
Rethinking the Datacenter
Sponsored by HP
Today's datacenters need to increase utilization, get control over power and cooling costs, and align with business objectives. Download this eBook to learn about the challenges facing the data center in a world where digital information is growing at a torrid pace and costs are being held in check. Learn more. »
|
|
Putting the Green into IT
Sponsored by HP
Electricity use in data centers is skyrocketing, sending energy bills through the roof, creating environmental concerns and generating negative publicity. "Going Green" means looking to technologies like virtualization, energy-efficient chips and racks, and implementing policies that extend beyond the data center. Learn more. »
|
|
Managing the Modern Network
Sponsored by HP
In a global economy where information crosses the globe in an instant, and where Web-based applications power business, it's more important than ever to ensure your network is safe from threats and optimized to deliver the data your business needs. »
|
|
Evaluating Software as a Service for Your Business
Sponsored by Webroot
Is Software as a Service just hype, or is something really going on here? See if your company can benefit as SaaS tries to change the face of the enterprise.
»
|
|
Is Your Disaster Recovery Plan Good Enough?
Sponsored by HP
Preparing for a disaster is more often than not part of the storage planning process, and it is one of the most difficult tasks, since it includes local hardware and software, networking equipment, and a test plan. Learn how to get disaster recovery right. »
|
|
|
|
|
|
Working with CDONTS
July 31, 2000
All that remains to be done at this point is to process the submitted form
data; and, as I told you in the beginning, we are going to send the data
via email to your email account using Windows NT Server's Collaboration
Data Object (CDONTS).
However, to use CDONTS, we ought to know what it is first. The
Collaboration Data Object, according to some
Microsoft documentation:
"CDONTS is a Simple Mail Transfer Protocol (SMTP) specific OLE server
that is specifically designed to provide Messaging functionality to
Web-based applications."
In non-Microsoftese, that means CDONTS is something that acts as the
middleman between your web page and the SMTP server, enabling
communication that will allow you to send data from the web (like our form)
to someone via email.
CDONTS is very powerful and feature-rich, but for now, we are going to
keep it simple. I will provide links for some other tutorials on CDONTS
at the end of this page. First things first, whenever you use a server
object like CDONTS you need to invoke an instance of it (or, in simpler
terms, make it available for use). To do that we are going to add a few
lines to our form handling code. All the code for CDONTS is explained
line-by-line following the example.
<%
if Request.Querystring("isSubmitted") = "yes" then
Dim fname, lname
Dim objCDO
fname = Request.Querystring("First_Name")
lname = Request.Querystring("Last_Name")
'Here is where we insert new code to invoke CDONTS
'This line invokes the object using the name objCDO
Set objCDO = Server.CreateObject("CDONTS.NewMail")
objCDO.From = "corinth@enfused.com" 'That's me :)
objCDO.To = "youremail@domain.com"
objCDO.Cc = "someoneimportant@whitehouse.gov, buycheese@cheese.com"
objCDO.Bcc = "bgates@microsoft.NET"
objCDO.Subject = "Submitted form data from my page"
objCDO.Body = "Name: " & fname & " " & lname
objCDO.BodyFormat = 1
objCDO.MailFormat = 1
objCDO.Send
'Notice that response.write changed to ConfirmMsg =
'I will explain why in just a little while.
ConfirmMsg = "Thanks for submitting your name!"
end if
%>
Now, let's go through that line-by-line, so you know exactly what is
going on. Keep in mind that everytime you want to reference a method or
property of the object you invoked, you need to use the name you
assigned (in this example, objCDO followed by a
period, as illustrated below. (Note: It does not matter in what order
these values are assigned, so long as they all precede the
Send command).
To begin, From is the email address, as a string, of
the user sending the email. For now, make this your email address.
Normally it would be wise to allow the user to fill this field in, and I
will show you how to do that at the end of the article. However, I
recommend that you try it on your own first to ensure you have a grasp
on what we have been doing thus far.
objCDO.From = "corinth@enfused.com" 'That's me :)
|
TIP: Do not send me spam
|
On the
other hand, all legitimate emails, questions, comments or
criticisms are welcome. Just keep in mind that I am a
busy guy and may not be able to reply very promptly to
all of them.
|
To is the email address of the intended recipient.
Make this field your email address(es). Multiple Addresses may be
separated by commas (in any field as a matter of fact). Do not forget
the quotes in any of these fields, they must all be string values.
objCDO.To = "youremail@domain.com"
CC, BCC are the email addresses
of any Carbon Copies or Blind Carbon Copies you would like to send.
objCDO.Cc = "someoneimportant@whitehouse.gov, buycheese@cheese.com"
objCDO.Bcc = "bgates@microsoft.NET"
Subject is any string you provide that will be
displayed as the subject of the email,
objCDO.Subject = "Submitted form data from my page"
Body is the body, or main content, of the message.
You can put anything you want in here, in the format of a string, so long
as it can be sent via email. We are just going to put our variables in here
and send them.
objCDO.Body = "Name: " & fname & " " & lname
|
TIP:
The above code illustrates an important and powerful
element of ASP and CDONTS, the designer can assign
variables to these CDONTS attributes rather then using
hard-coded strings. That ability expands your capacity
to work creatively. Try to come up with some ways to
make your life easier by using string variables.
Perhaps you could make the subject a form field, thereby
allowing users to submit their own subject.
|
The next two properties determine the type of email sent, whether it is
HTML or plain text. For our purposes, we will be sending the message
as plain text. However, should you want to send HTML simply change
these values to 0 and make the Body string HTML code.
objCDO.BodyFormat = 1
objCDO.MailFormat = 1
Finally, the last bit of code actually tells the server to send the message.
objCDO.Send
As for that little trick with ConfirmMsg = instead of
Response.Write, that was done in order to better
format our confirmation message. When we apply the final touches to the
whole page, I will show you what we are going to do with the
ConfirmMsg variable.
That is really all there is to CDONTS, at least for our purposes. I have
created a
handy CDONTS reference table to help
you while you are coding. All that remains is for you to move onto the
next page where we will put it all together and I will show you a few
extras you can add in, should you so desire.
CDONTS Links:
ASP Today: Setting Up and Using CDONTS
15 Seconds: Sending HTML with CDO
15 Seconds: Collaboration Data Object and IIS 4.0
Power ASP: Using the CDONTS component...(includes attachments).
ASP Watch: Sending E-mail using CDONTS
Microsoft CDONTS Documentation
Making the ASP Page Smart
Using ASP for Form Handling
Putting It All Together and Wrapping Up
|