Knowledgebase: Windows
Do you have any CDO How to Example's
Posted by Barry Tarbet on 23 August 2006 07:09 AM

Please Note - CDONTS object library doesn't work on Windows 2003. We recommend using CDO instead of CDONTS on all Windows servers, since it is a newer and more flexible. // Example 1 < % set objMail=CreateObject("CDO.Message") objMail.To="Target@mail.net" objMail.From="Source@Mail.net" objMail.Subject="my test" objMail.HTMLBody = "hello" objMail.Send set objMail=Nothing %> // Example 2 < !--METADATA TYPE="typelib" UUID="00000205-0000-0010-8000-00AA006D2EA4" NAME="ADODB Type Library" -->

 

---------

<%
 '----------------------------------------------------------------------------
 '
 ' Send email using the CDOSYS component
 '
 ' by Chris Hardy
 ' http://www.chrishardy.co.uk/
 '
 '----------------------------------------------------------------------------

  Option Explicit

  dim sName, sEmail, sMessage
 dim oCdoMail, oCdoConf, sConfURL

  if Request.Form("Action") <> "" then
  sName = Request.Form("Name")
  sEmail = Request.Form("Email")

  sMessage = Request.Form("Message")

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

 sConfURL = "http://schemas.microsoft.com/cdo/configuration/"

 with oCdoConf
 .Fields.Item(sConfURL & "sendusing") = 2
 .Fields.Item(sConfURL & "smtpserver") = "mail.yourdomain.com"
 .Fields.Item(sConfURL & "smtpserverport") = 25
 .Fields.Update
 end with

with oCdoMail
.From = "webmaster@yourdomain.com"
.To = sEmail
.Subject = "My message subject"
.TextBody = sMessage
.HTMLBody = sMessage
.Configuration = oCdoConf
.Send
end with

Set oCdoConf = Nothing
Set oCdoMail = Nothing

response.write "Thanks for your message!"
 else
%>
<form method="post" action="<%=Request.ServerVariables("SCRIPT_NAME")%>">
<p>Name:<br /><input type="text" name="Name" /></p>
<p>E-mail:<br /><input type="text" name="Email" /></p>
<p>Message:<br /><textarea name="Message"></textarea></p>
<p><input type="submit" name="Action" value="Send" /></p>
</form>
<%
end if
%>

 

 

(671 vote(s))
Helpful
Not helpful

Comments (0)
Post a new comment
 
 
Full Name:
Email:
Comments:
CAPTCHA Verification 
 
Please enter the text you see in the image into the textbox below (we use this to prevent automated submissions).