Web Hosting, Linux Hosting, Windows Hosting Provider  
Windows Hosting Linux Hosting VPS Hosting JSP Hosting E-Mail Hosting Reseller Hosting Support Contact Us

ASP Email – 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 ZetaClear
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.

RSS feed for comments on this post · TrackBack URL

Leave a Comment

You must be logged in to post a comment.


find hidden objects