Web Hosting - Dedicated Servers
Dedicated Server Hosting
Web Hosting eCommerce Hosting Reseller Hosting Reseller Hosting Dedicated Server
Register Your Domain Name Todaywww

ASP Sending Email Using CDOSYS on Windows Hosting

User Rating: / 3
PoorBest 

CDOSYS is a built-in component in ASP. This component is used to send e-mails with ASP.

Sending e-mail with CDOSYS

CDO (Collaboration Data Objects) is a Microsoft technology that is designed to simplify the creation of messaging applications. CDOSYS is a built-in component in ASP and is what is available on our servers for the purpose of sending mail on our Windows ASP Hosting options which are run on our Windows Server 2003 environment.

Since Windows 2003 appeared, CDONTS have been dropped in favour of CDOSYS. The following tutorial shows you how to code a mailform that will send ASP email using CDOSYS:

We start by creating a mail object and a configuration object to use with it:

<%
Set oCdoMail = Server.CreateObject("CDO.Message")
Set oCdoConf = Server.CreateObject("CDO.Configuration")
%>

Set the configuration object up as shown below. You then need to set the SMTP server item, to send through the local mail server, use "localhost". The default SMTP port is 25.

<%
sConfURL = "http://schemas.microsoft.com/cdo/configuration/"
with oCdoConf
.Fields.Item(sConfURL & "sendusing") = 2
.Fields.Item(sConfURL & "smtpserver") = "localhost"
.Fields.Item(sConfURL & "smtpserverport") = 25
.Fields.Update
end with
%>

Now you can set up your recipients replacing the information below as required. You can send to multiple recipients by seperating addresses with a semicolon, as shown with the To property below:

<%
with oCdoMail
.From = " This e-mail address is being protected from spam bots, you need JavaScript enabled to view it "
.To = " This e-mail address is being protected from spam bots, you need JavaScript enabled to view it ; This e-mail address is being protected from spam bots, you need JavaScript enabled to view it "
.CC = " This e-mail address is being protected from spam bots, you need JavaScript enabled to view it "
.BCC = " This e-mail address is being protected from spam bots, you need JavaScript enabled to view it "
end with
%>

Set the Subject and Body text and we're almost there. To send plain text email, use the TextBody method. To send HTML email, use the HTMLBody method.

You can also add an attachment to your message by using the AddAttachment method:

<%
with oCdoMail
.Subject = "My message subject"
.TextBody = "This is a plain text email"
.HTMLBody = "This is an HTML email"
.AddAttachment = "\path\to\your\file"
end with
%>

And that's just about it, all we need to do now is bind the configuration to the CDO Message and send the email:

<%
oCdoMail.Configuration = oCdoConf
oCdoMail.Send
Set oCdoConf = Nothing
Set oCdoMail = Nothing
%>

Don't forget to destroy the configuration and mail objects we've used. You can download the example script here: right click save-as cdosys.zip

To read more on this topic there are numerous examples available via a Google search, I would also recommend the official Microsoft ASP Developer's website & community resources available at http://www.asp.net


Newer news items:
Older news items:




If you found this tutorial helpful, you can bookmark it with your favourite tracker.

Reddit!Del.icio.us!Google!Live!Facebook!Slashdot!Netscape!Technorati!Blinklist!Yahoo!Ma.gnolia!Squidoo!
 
< Prev   Next >
 
 
RedHat Linux
cPanel Hosting
plesk windows
Fantastico SiteBuilder
 

AUSWEB Web Hosting PTY LTD © 2008 Network Info Data CenterPrivacy PolicySLA Terms and Conditions