• Sending
email with CDOSYS using ASP |
Since Windows XP, Microsoft is no longer including CDONTS on its
operating systems. Instead it uses the new and more powerful mail
component CDOSYS that was already present in Windows 2000.
It is still fairly simple to send a simple email although some
more advanced functions are a bit more complex. I'll show
you how to send a simple email and how to add additional advanced
configuration parameters.
The Object (CDO.Message) has several properties and methods
that you must know:
.From |
E-mail address of the sender |
.To |
E-mail address of the recipient |
.CC |
E-mail address of the CC recipient |
.Subject |
Subject of the message |
.TextBody |
Body of the message in plain text |
.HTMLBody |
Body of the message in HTML |
.Send |
Calling this method the message is sent |
The following example is the simplest email you can send. As you
can see it couldn't be easier:
<%
Dim sMsg
Dim sTo
Dim sFrom
Dim sSubject
Dim sTextBody
sTo = "recipient@maildomain.com"
sFrom = "fromaddress@maildomain.com"
sSubject = "Insert here your subject text"
sTextBody = "Insert here your plain body text"
Dim objMail
'Create the mail object
Set objMail = Server.CreateObject("CDO.Message")
'Set key properties
objMail.From = sFrom
objMail.To = sTo
objMail.Subject= sSubject
objMail.TextBody = sTextBody
'Send the email
objMail.Send
'Clean-up mail object
Set objMail = Nothing
%> |
The next example (see link to code below) shows a more complex
scenario. The first thing it does in create a new configuration
object in addition to the mail object. Then it applies settings to
the configuration object like the SMTP server authentication
(optional), the SMTP server name and port and whether the mail
should be sent securely using SSL.
The next step is configure the mail object with an optional CC
address (if it is empty it won't set it) and send it. Do not
forget to clean-up the mail objects by setting them to nothing
once you're done with them.
You can see the code
here.
I hope you found this useful!
|