D
DigitalRick
I have been running CDONTS in my ASPpages to send emails to me sent from my
guestbook. It had been working fine untill I upgraded to Server 2003 (I am
also running Exchange 2003) all locally. I will include the code I
originally used. I understand I should switch from CDONTS to CDO mail but
after several sttempts I am finding a very hard time getting the new CDO mail
to work properly. Any assistance with this would be greatly appreciated.
Here is the code:
------------------------------------------------------------------------------------------------
'Set the response buffer to true so we execute all asp code before sending
the HTML to the clients browser
Response.Buffer = True
'Dimension variables
Dim strBody 'Holds the body of the e-mail
Dim objCDOMail 'Holds the mail server object
Dim strMyEmailAddress 'Holds your e-mail address
Dim strCCEmailAddress 'Holds any carbon copy e-mail addresses if you want
to send carbon copies of the e-mail
Dim strBCCEmailAddress 'Holds any blind copy e-mail addresses if you wish
to send blind copies of the e-mail
Dim strReturnEmailAddress 'Holds the return e-mail address of the user
'----------------- Place your e-mail address in the following sting
-----------------------
strMyEmailAddress = "(e-mail address removed)"
'----------- Place Carbon Copy e-mail address's in the following sting,
separated by ; --------------
strCCEmailAddress = "" 'Use this string only if you want to send the carbon
copies of the e-mail
'----------- Place Blind Copy e-mail address's in the following sting,
separated by ; --------------
strBCCEmailAddress = "" 'Use this string only if you want to send the blind
copies of the e-mail
'------------------------------------------------------------------------------------------------
'Read in the users e-mail address
strReturnEmailAddress = Request.Form("email")
'Initialse strBody string with the body of the e-mail
strBody = "<h2>E-mail sent from form on Web Site</h2>"
strBody = strBody & "<br><b>Name: </b>" & Request.Form("firstName") & " " &
Request.Form("lastName")
strBody = strBody & "<br><b>E-mail: </b>" & strReturnEmailAddress
strBody = strBody & "<br><br><b>Comments: - </b><br>" &
Replace(Request.Form("enquiry"), vbCrLf, "<br>")
'Check to see if the user has entered an e-mail address and that it is a
valid address otherwise set the e-mail address to
your own otherwise the e-mail will be rejected
If Len(strReturnEmailAddress)
< 5 OR NOT Instr(1, strReturnEmailAddress, " ") = 0 OR InStr(1,
strReturnEmailAddress, "@", 1)
< 2 OR InStrRev(strReturnEmailAddress, ".") < InStr(1,
strReturnEmailAddress, "@", 1) Then
'Set the return e-mail address to your own
strReturnEmailAddress = strMyEmailAddress
End If
'Send the e-mail
'Create the e-mail server object
Set objCDOMail = Server.CreateObject("CDONTS.NewMail")
'Who the e-mail is from (this needs to have an e-mail address in it for the
e-mail to be sent)
objCDOMail.From = Request.Form("firstName") & " " & Request.Form("lastName")
& " <" & strReturnEmailAddress & ">"
'Who the e-mail is sent to
objCDOMail.To = strMyEmailAddress
'Who the carbon copies are sent to
objCDOMail.Cc = strCCEmailAddress
'Who the blind copies are sent to
objCDOMail.Bcc = strBCCEmailAddress
'Set the e-mail body format (0=HTML 1=Text)
objCDOMail.BodyFormat = 0
'Set the mail format (0=MIME 1=Text)
objCDOMail.MailFormat = 0
'Set the subject of the e-mail
objCDOMail.Subject = "Guestbook Submission"
'Set the main body of the e-mail
objCDOMail.Body = strBody
'Importance of the e-mail (0=Low, 1=Normal, 2=High)
objCDOMail.Importance = 1
'Send the e-mail
objCDOMail.Send
'Close the server object
Set objCDOMail = Nothing
%>
<html>
<head>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<title>Thank you</title>
</head>
<body text="#000000" bgcolor="#FFFFFF" link="#0000FF" vlink="#990099"
alink="#FF0000">
<table width="95%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td height="2">
<h1 align="center">Success !! !! !!</h1>
</td>
</tr>
</table>
<br>
<br>
<table width="85%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td align="center"><B><h3> Thank-you <% = Request.Form("firstName")
%> <% = Request.Form("lastName") %>
for signing our guestbook. </h3>
<br>
</td>
</tr>
</table>
------------------------------------------------------------------------------------------------
Not sure if this is necessary or not but this is the code from the guestbook
front page.....
------------------------------------------------------------------------------------------------
<!-- Javascript function to check the submitted form has been filled in
correctly before submitting -->
<SCRIPT language="JavaScript">
<!-- Hide from older browsers
//Check the enquiry form is filled in correctly
function CheckForm () {
//Initialise variables
var errorMsg = "";
//Check for a first name
if (document.frmEnquiry.firstName.value == ""){
errorMsg += "\n\tFirst Name \t- Enter your First Name";
}
//Check for a last name
if (document.frmEnquiry.lastName.value == ""){
errorMsg += "\n\tLast Name \t- Enter your Last Name";
}
//Check for an e-mail address and that it is valid
if ((document.frmEnquiry.email.value == "") ||
(document.frmEnquiry.email.value.length > 0 &&
(document.frmEnquiry.email.value.indexOf("@",0) == - 1 ||
document.frmEnquiry.email.value.indexOf(".",0) == - 1))) {
errorMsg += "\n\tE-mail Address \t- Enter your valid e-mail address";
}
//Check for an enquiry
if (document.frmEnquiry.enquiry.value == "") {
errorMsg += "\n\tComments \t\t- Enter comments please";
}
//If there is aproblem with the form then display an error
if (errorMsg != ""){
msg = "______________________________________________________________\n\n";
msg += "Your guestbook submition has not been sent because there are
problem(s) with the form.\n";
msg += "Please correct the problem(s) and re-submit the form.\n";
msg += "______________________________________________________________\n\n";
msg += "The following field(s) need to be corrected: -\n";
errorMsg += alert(msg + errorMsg + "\n\n");
return false;
}
return true;
}
// -->
</script>
<!-- Close the HTML document head -->
</head>
<!-- Start the HTML body -->
' <body text="#000000" bgcolor="#FFFFFF" link="#0000FF" vlink="#990099"
alink="#FF0000">
<table width="95%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td> <br>
<h1 align="center">Please sign our GuestBook</h1>
</td>
</tr>
</table>
<table width="85%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td>
<table width="90%" border="0" align="center" cellpadding="0"
cellspacing="0">
<tr>
<td>
<form method="post" name="frmEnquiry" action="thanks.asp"
onSubmit="return CheckForm();">
<table width="450" border="0" align="center" cellpadding="0"
cellspacing="0" >
<!-- First tabe row -->
<tr>
<td colspan="3"> <font size="2"> *Indicates required fields
</b></font>
</tr>
<!-- second table row -->
<tr>
<td width="265"><B>First Name* <br>
<input maxlength="30" name="firstName">
</td>
<!-- Coloum two in the second table row -->
<td width="185" colspan="2"><B>Last Name* <br>
<input maxlength="30" name="lastName">
</td>
</tr>
<!-- Third table row spread over 3 coloumns -->
<tr>
<td width="265"><B>E-mail Address* <br>
<input maxlength="255" name="email">
</td>
<td width="185" colspan="2"> </td>
</tr>
<td colspan="3" height="170"><B>Comments* <br>
<textarea name="enquiry" cols="50" rows="10"></textarea>
</td>
</tr>
<tr align="center">
<td colspan="3" height="36">
<input type="submit" name="Submit" value="Submit">
<input type="reset" name="Reset" value="Clear Form">
</td>
</tr>
</table>
</form>
</td>
</tr>
</table>
</td>
</tr>
</table>
guestbook. It had been working fine untill I upgraded to Server 2003 (I am
also running Exchange 2003) all locally. I will include the code I
originally used. I understand I should switch from CDONTS to CDO mail but
after several sttempts I am finding a very hard time getting the new CDO mail
to work properly. Any assistance with this would be greatly appreciated.
Here is the code:
------------------------------------------------------------------------------------------------
'Set the response buffer to true so we execute all asp code before sending
the HTML to the clients browser
Response.Buffer = True
'Dimension variables
Dim strBody 'Holds the body of the e-mail
Dim objCDOMail 'Holds the mail server object
Dim strMyEmailAddress 'Holds your e-mail address
Dim strCCEmailAddress 'Holds any carbon copy e-mail addresses if you want
to send carbon copies of the e-mail
Dim strBCCEmailAddress 'Holds any blind copy e-mail addresses if you wish
to send blind copies of the e-mail
Dim strReturnEmailAddress 'Holds the return e-mail address of the user
'----------------- Place your e-mail address in the following sting
-----------------------
strMyEmailAddress = "(e-mail address removed)"
'----------- Place Carbon Copy e-mail address's in the following sting,
separated by ; --------------
strCCEmailAddress = "" 'Use this string only if you want to send the carbon
copies of the e-mail
'----------- Place Blind Copy e-mail address's in the following sting,
separated by ; --------------
strBCCEmailAddress = "" 'Use this string only if you want to send the blind
copies of the e-mail
'------------------------------------------------------------------------------------------------
'Read in the users e-mail address
strReturnEmailAddress = Request.Form("email")
'Initialse strBody string with the body of the e-mail
strBody = "<h2>E-mail sent from form on Web Site</h2>"
strBody = strBody & "<br><b>Name: </b>" & Request.Form("firstName") & " " &
Request.Form("lastName")
strBody = strBody & "<br><b>E-mail: </b>" & strReturnEmailAddress
strBody = strBody & "<br><br><b>Comments: - </b><br>" &
Replace(Request.Form("enquiry"), vbCrLf, "<br>")
'Check to see if the user has entered an e-mail address and that it is a
valid address otherwise set the e-mail address to
your own otherwise the e-mail will be rejected
If Len(strReturnEmailAddress)
< 5 OR NOT Instr(1, strReturnEmailAddress, " ") = 0 OR InStr(1,
strReturnEmailAddress, "@", 1)
< 2 OR InStrRev(strReturnEmailAddress, ".") < InStr(1,
strReturnEmailAddress, "@", 1) Then
'Set the return e-mail address to your own
strReturnEmailAddress = strMyEmailAddress
End If
'Send the e-mail
'Create the e-mail server object
Set objCDOMail = Server.CreateObject("CDONTS.NewMail")
'Who the e-mail is from (this needs to have an e-mail address in it for the
e-mail to be sent)
objCDOMail.From = Request.Form("firstName") & " " & Request.Form("lastName")
& " <" & strReturnEmailAddress & ">"
'Who the e-mail is sent to
objCDOMail.To = strMyEmailAddress
'Who the carbon copies are sent to
objCDOMail.Cc = strCCEmailAddress
'Who the blind copies are sent to
objCDOMail.Bcc = strBCCEmailAddress
'Set the e-mail body format (0=HTML 1=Text)
objCDOMail.BodyFormat = 0
'Set the mail format (0=MIME 1=Text)
objCDOMail.MailFormat = 0
'Set the subject of the e-mail
objCDOMail.Subject = "Guestbook Submission"
'Set the main body of the e-mail
objCDOMail.Body = strBody
'Importance of the e-mail (0=Low, 1=Normal, 2=High)
objCDOMail.Importance = 1
'Send the e-mail
objCDOMail.Send
'Close the server object
Set objCDOMail = Nothing
%>
<html>
<head>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<title>Thank you</title>
</head>
<body text="#000000" bgcolor="#FFFFFF" link="#0000FF" vlink="#990099"
alink="#FF0000">
<table width="95%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td height="2">
<h1 align="center">Success !! !! !!</h1>
</td>
</tr>
</table>
<br>
<br>
<table width="85%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td align="center"><B><h3> Thank-you <% = Request.Form("firstName")
%> <% = Request.Form("lastName") %>
for signing our guestbook. </h3>
<br>
</td>
</tr>
</table>
------------------------------------------------------------------------------------------------
Not sure if this is necessary or not but this is the code from the guestbook
front page.....
------------------------------------------------------------------------------------------------
<!-- Javascript function to check the submitted form has been filled in
correctly before submitting -->
<SCRIPT language="JavaScript">
<!-- Hide from older browsers
//Check the enquiry form is filled in correctly
function CheckForm () {
//Initialise variables
var errorMsg = "";
//Check for a first name
if (document.frmEnquiry.firstName.value == ""){
errorMsg += "\n\tFirst Name \t- Enter your First Name";
}
//Check for a last name
if (document.frmEnquiry.lastName.value == ""){
errorMsg += "\n\tLast Name \t- Enter your Last Name";
}
//Check for an e-mail address and that it is valid
if ((document.frmEnquiry.email.value == "") ||
(document.frmEnquiry.email.value.length > 0 &&
(document.frmEnquiry.email.value.indexOf("@",0) == - 1 ||
document.frmEnquiry.email.value.indexOf(".",0) == - 1))) {
errorMsg += "\n\tE-mail Address \t- Enter your valid e-mail address";
}
//Check for an enquiry
if (document.frmEnquiry.enquiry.value == "") {
errorMsg += "\n\tComments \t\t- Enter comments please";
}
//If there is aproblem with the form then display an error
if (errorMsg != ""){
msg = "______________________________________________________________\n\n";
msg += "Your guestbook submition has not been sent because there are
problem(s) with the form.\n";
msg += "Please correct the problem(s) and re-submit the form.\n";
msg += "______________________________________________________________\n\n";
msg += "The following field(s) need to be corrected: -\n";
errorMsg += alert(msg + errorMsg + "\n\n");
return false;
}
return true;
}
// -->
</script>
<!-- Close the HTML document head -->
</head>
<!-- Start the HTML body -->
' <body text="#000000" bgcolor="#FFFFFF" link="#0000FF" vlink="#990099"
alink="#FF0000">
<table width="95%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td> <br>
<h1 align="center">Please sign our GuestBook</h1>
</td>
</tr>
</table>
<table width="85%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td>
<table width="90%" border="0" align="center" cellpadding="0"
cellspacing="0">
<tr>
<td>
<form method="post" name="frmEnquiry" action="thanks.asp"
onSubmit="return CheckForm();">
<table width="450" border="0" align="center" cellpadding="0"
cellspacing="0" >
<!-- First tabe row -->
<tr>
<td colspan="3"> <font size="2"> *Indicates required fields
</b></font>
</tr>
<!-- second table row -->
<tr>
<td width="265"><B>First Name* <br>
<input maxlength="30" name="firstName">
</td>
<!-- Coloum two in the second table row -->
<td width="185" colspan="2"><B>Last Name* <br>
<input maxlength="30" name="lastName">
</td>
</tr>
<!-- Third table row spread over 3 coloumns -->
<tr>
<td width="265"><B>E-mail Address* <br>
<input maxlength="255" name="email">
</td>
<td width="185" colspan="2"> </td>
</tr>
<td colspan="3" height="170"><B>Comments* <br>
<textarea name="enquiry" cols="50" rows="10"></textarea>
</td>
</tr>
<tr align="center">
<td colspan="3" height="36">
<input type="submit" name="Submit" value="Submit">
<input type="reset" name="Reset" value="Clear Form">
</td>
</tr>
</table>
</form>
</td>
</tr>
</table>
</td>
</tr>
</table>