ASP Email - CDOSYS
Since Windows 2003 appeared, CDONTS has been dropped in favour of CDOSYS. This tutorial shows you how to send ASP email with 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 might have to change the SMTP server item from "localhost" to point to your web hosts SMTP server. The default port is 25, which you may also have to change - again, check with your web host.
<%
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 we can set up our recipients. You can send to multiple recipients by seperating addresses with a semicolon, as shown with the To property below:
<%
with oCdoMail
.From = "you@yourdomain.com"
.To = "someone@domain.com; somebody@domain.com"
.CC = "someone.else@domain.com"
.BCC = "someone@anotherdomain.com"
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 = "<b>This is an HTML email</b>"
.AddAttachment = "C:\Inetpub\wwwroot\attachment.zip"
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.

