HitNet Customer Portal Language
 
HomeKnowledge Basee-Maile-Mailing a Web Form using CDOSYS
Information
Article ID10
Created On8/8/2008
Modified8/8/2008
e-Mailing a Web Form 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 will have to change the SMTP server item from "smtp.yourdomainname.com" to point to your web hosts SMTP server. The default port is 25, which you may also have to change.

<%
sConfURL = "http://schemas.microsoft.com/cdo/configuration/"
with oCdoConf
    .Fields.Item(sConfURL & "sendusing") = 2
    .Fields.Item(sConfURL & "smtpserver") = "smtp.yourdomainname.com"
    .Fields.Item(sConfURL & "smtpserverport") = 25
    .Fields.Item(sConfURL & "smtpusessl") = "False"
    .Fields.Item(sConfURL & "smtpconnectiontimeout") = 60
    .Fields.Item(sConfURL & "smtpauthenticate") = 1
    .Fields.Item(sConfURL & "sendusername") = "youremail@yourdomainname.com"
    .Fields.Item(sConfURL & "sendpassword") = "password"
    .Fields.Update
end with
%>

Now we can set up our recipients. You can send to multiple recipients by separating 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>"
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.