-----Original Message-----
I am trying to create a CDONTS asp page to pull contents
from a form and send to the correct distribution list.
I am having a problew with the TO property. If I set it
static (mailer.to = "(e-mail address removed)) it all works
fine. I want it to change based on a value from the form
and build a string for it:
mailer.to= strDistibutionList
where
strDisributionList = "(e-mail address removed); (e-mail address removed)).
It does not send it to anyone then.
I agree that the CDO.Message object is far superior to
CDONTS.NewMail. Here's a simple example that uses
CDO.Message.
<body>
<form method="POST">
<input type="text" name="txtBody" size="20"><p>
<input type="submit" value="Submit" name="btnSub"></p>
</form>
<%
Const cdoSchema = _
"
http://schemas.microsoft.com/cdo/configuration/"
if request("btnSub") <> "" then
Set objMsg = CreateObject("CDO.Message")
objMsg.Subject = "Test " & now()
objMsg.Sender = "(e-mail address removed)"
objMsg.To = "(e-mail address removed), (e-mail address removed)"
objMsg.TextBody = "The text box said, """ & _
request("txtBody") & """."
objMsg.Configuration.Fields.Item(cdoSchema & _
"sendusing") = 2
objMsg.Configuration.Fields.Item(cdoSchema & _
"smtpserver") = "smtp.whatever.com"
objMsg.Configuration.Fields.Item(cdoSchema & _
"smtpserverport") = 25
objMsg.Configuration.Fields.Update
objMsg.Send
end if
%>
</body>
This code presumes that the form has a Submit button named
btnSub. The statement
if request("btnSub") <> "" then
'
end if
therefore tests whether the form is running because the
visitor clicked a hyperlink on another page, or because
the visitor clicked the Submit button.
You can change the objMsg.TextBody = statement to format
the body of the message any way you want. Use the built-in
constant vbCrLf to create line breaks.
Alternatively, you can set objMsg.HtmlBody to a mess of
HTML, and the object will send HTML-formatted mail. Here's
an example.
objMsg.HtmlBody = _
"<html>" & vbCrLf & _
"<body>" & vbCrLf & _
"<table>" & vbCrLf & _
" <tr>" & vbCrLf& _
" <td>Name</td>" & vbCrLf& _
" <td>" & request("Name") & "</td>" & vbCrLf& _
" </tr>" & vbCrLf & _
" <tr>" & vbCrLf& _
" <td>Address</td>" & vbCrLf& _
" <td>" & request("Address") & "</td>" & vbCrLf& _
" </tr>" & vbCrLf & _
"</table>" & _
"</body>" & _
"</html>"
And of course, you'll want to change the subject, the
sender address, the To address, and the smtp server name
as well.
Jim Buyens
Microsoft FrontPage MVP
http://www.interlacken.com
Author of:
*----------------------------------------------------
|\---------------------------------------------------
|| Microsoft Office FrontPage 2003 Inside Out
||---------------------------------------------------
|| Web Database Development Step by Step .NET Edition
|| Microsoft FrontPage Version 2002 Inside Out
|| Faster Smarter Beginning Programming
|| (All from Microsoft Press)
|/---------------------------------------------------
*----------------------------------------------------