Live chat by BoldChat

Using CDONTS

 

This page gives some examples of how to use CDONTS on NetBenefit Win2K and Win2KCF web space.

Please note that CDONTS does not work on Win2003 webspace; you need to use CDOSYS.

As CDOSYS works on Win2000 and Win2003, we recommend that you use CDOSYS to avoid having to recode if you later upgrade.

  1. Using CDONTS to send text formatted messages
  2. Using CDONTS to send HTML formatted messages
  3. Getting CDONTS to send a carbon copy (CC) or blind carbon copy (BCC)
  4. Getting CDONTS to send mail from a "friendly" name
  5. Example form-to-email

1. Using CDONTS to send text formatted messages

<%
    Set MailObj = CreateObject("CDONTS.NewMail")
    MailObj.From = "sender@mydomain.com"
    MailObj.To = "recipient@theirdomain.com"
    MailObj.Subject = "Test message"
    Text = "Thank you for your submission." & chr(13) & chr(10)
    Text = Text & "Your request is being processed." & chr(13) & chr(10)
    Text = Text & "Please allow 48 hours for a response."
    MailObj.Body = Text
    MailObj.Send
    Set MailObj = nothing
%>

2. Using CDONTS to send HTML formatted messages

<%
    Set MailObj = CreateObject("CDONTS.NewMail")
    MailObj.From = "sender@mydomain.com"
    MailObj.To = "recipient@theirdomain.com"
    MailObj.Subject = "Test message"
    HTML = "<!DOCTYPE HTML PUBLIC""-//IETF//DTD HTML//EN"">"
    HTML = HTML & "<html>"
    HTML = HTML & "<head>"
    HTML = HTML & "<title>Test CDOSYS Email in HTML format</title>"
    HTML = HTML & "</head>"
    HTML = HTML & "<body bgcolor=""FFFFFF"">"
    HTML = HTML & "<p><font size =""3"" face=""Arial"">"
    HTML = HTML & "<b>My Company Ltd.</b><br>"
    HTML = HTML & "Your subscription newsletter</p>"
    HTML = HTML & "<p align = ""center"">In this newsletter we announce a new product.</p>"
    HTML = HTML & "</body>"
    HTML = HTML & "</html>"
    MailObj.BodyFormat = 0
    MailObj.MailFormat = 0
    MailObj.Body = HTML
    MailObj.Send
    Set MailObj=nothing
%>

Note:
MailObj.BodyFormat = 0 sets the mail to HTML format (leave unspecified or set to = 1 for plain text).
MailObj.MailFormat = 0 sets the mail to MIME encoded (leave unspecified or set to = 1 for plain text).

3. Getting CDONTS to send a carbon copy (CC) or blind carbon copy (BCC)

You would include a line such as:

    MailObj.Cc = "cc@ccdomain.com"
    MailObj.Bcc = bcc@bccdomain.com

4. Getting CDONTS to send mail from a "friendly" name

Enclose the email address in angle brackets, e.g:

    MailObj.From = "Mr Sender <sender@mydomain.com>"

Save the following script as a file called sendmail.asp.

5. Example form-to-email

<% Response.Buffer = True %>
<!--- sendmail.asp CDONTS version--->
<!--- This file is a generic sendmail utility which --->
<!--- takes a form and processes the fields --->
<!--- accordingly. --->
<!--- Hidden control fields should include --->
<!--- recipient:- who to send the email to --->
<!--- subject: - the subject of the mail message --->
<!--- redirect: - next page to show after submission --->
<!--- from: - where the message is coming from. --->
<!--- - This must be a VALID email address. --->
<%
Set MailObj = CreateObject("CDONTS.NewMail")
MailObj.From = Trim(Request.Form("from"))
MailObj.To = Trim(Request.Form("recipient"))
MailObj.Subject = Trim(Request.Form("subject"))
Text = ""

For Each FieldName in Request.Form
For Each FieldValue in Request.Form(FieldName)
If LCase(FieldName) = "recipient" Or LCase(FieldName) = "subject"_
Or LCase(FieldName) = "redirect" Or LCase(FieldName) = "from" Then
Else
Text = Text & FieldName & " = " & FieldValue & chr(13) & chr(10)
End If
Next
Next

MailObj.Body = Text
MailObj.Send
Set MailObj = nothing
Response.Redirect Request.Form("redirect")
%>

Your form should then contain the special fields: recipient, subject, from, redirect.
The ACTION attribute of the form should be the above script.

<FORM METHOD="POST" ACTION="sendmail.asp">
<INPUT TYPE="HIDDEN" NAME="recipient" VALUE="[YOUR EMAIL ADDRESS]">
<INPUT TYPE="HIDDEN" NAME="subject" VALUE="[SUBJECT FOR MESSAGE]">
<INPUT TYPE="HIDDEN" NAME="redirect" VALUE="[THANKYOU PAGE]">
<INPUT TYPE="HIDDEN" NAME="from" VALUE="[FROM ADDRESS]">

Then have the rest of your form as normal, eg:

Message1:<INPUT TYPE="TEXT" NAME="Message1"><BR>
Message2:<INPUT TYPE="TEXT" NAME="Message2"><BR>
<INPUT TYPE="Submit" VALUE="Send Mail"><BR>
</FORM>