Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CDONTS e-mail problem

Status
Not open for further replies.

dcarbone

Programmer
Aug 22, 2003
29
CA
I am using CDONTS to send e-mail. However, this script sometimes gets out of control and sends the same e-mail out thousands of times per second. To stop sending, i have to stop SMTP and reinstall it. Does anyone know what this problem might be, or how to fix it?



<%
Dim strTo
Dim strSubject
Dim strBody
Dim strResponse
Dim objCDOMail

strTo = Request.Form(&quot;to&quot;)
strSubject = Request.Form(&quot;subject&quot;)
strBody = Request.Form(&quot;body&quot;)
strResponse = &quot;Message has been sent!&quot;

strBody = strBody & vbCrLf & vbCrLf

strBody = strBody & vbCrLf

If strTo = &quot;&quot; Or Not IsValidEmail(strTo) Then
%>
<FORM ACTION=&quot;./email.asp&quot; METHOD=&quot;post&quot;>
Select Department:<BR>
<select name=&quot;to&quot;>
<option value=&quot;dan@teleplanetcommunications.com&quot;>Administration</option>
<option value=&quot;andrew@teleplanetcommunications.com&quot;>Technical</option>
</select>

<br>

Subject:
<br>
<INPUT TYPE=&quot;text&quot; NAME=&quot;subject&quot; SIZE=&quot;30&quot;></INPUT><BR>

Message:
<br>
<TEXTAREA NAME=&quot;body&quot; ROWS=&quot;10&quot; COLS=&quot;40&quot; WRAP=&quot;virtual&quot;></TEXTAREA><BR>

<INPUT TYPE=&quot;submit&quot; VALUE=&quot;Send Message!&quot;></INPUT>
</FORM>
<%
Else
Set objCDOMail = Server.CreateObject(&quot;CDONTS.NewMail&quot;)

objCDOMail.From = &quot;Visitor <Server@tplanet.com>&quot;
objCDOMail.To = strTo
objCDOMail.Subject = strSubject
objCDOMail.Body = strBody

objCDOMail.Cc = &quot;user@domain.com;user@domain.com&quot;

objCDOMail.Send

Set objCDOMail = Nothing

Response.Write strResponse
End If
%>

<%
Function IsValidEmail(strEmail)
Dim bIsValid
bIsValid = True

If Len(strEmail) < 5 Then
bIsValid = False
Else
If Instr(1, strEmail, &quot; &quot;) <> 0 Then
bIsValid = False
Else
If InStr(1, strEmail, &quot;@&quot;, 1) < 2 Then
bIsValid = False
Else
If InStrRev(strEmail, &quot;.&quot;) < InStr(1, strEmail, &quot;@&quot;, 1) + 2 Then
bIsValid = False
End If
End If
End If
End If

IsValidEmail = bIsValid
End Function
%>

 
consider maybe placing all the code in fucntions/subs to make it easier to handle...

Code:
                         <%
                         Dim strTo
                         Dim strSubject
                         Dim strBody
                         Dim strResponse
                         Dim objCDOMail

                         strTo = Request.Form(&quot;to&quot;)
                         strSubject = Request.Form(&quot;subject&quot;)
                         strBody = Request.Form(&quot;body&quot;)
                         strResponse = &quot;Message has been sent!&quot;

                         strBody = strBody & vbCrLf & vbCrLf

                         strBody = strBody & vbCrLf

                         If strTo = &quot;&quot; Or Not IsValidEmail(strTo) Then
                            call show_form
                        else
                            call send_email
                        end if
                             

sub show_form()
<FORM ACTION=&quot;./email.asp&quot; METHOD=&quot;post&quot;>
                                 Select Department:<BR>
                                 <select name=&quot;to&quot;>
                                 <option value=&quot;dan@teleplanetcommunications.com&quot;>Administration</option>
                                 <option value=&quot;andrew@teleplanetcommunications.com&quot;>Technical</option>
                                 </select>
                                         
                                 <br>

                                 Subject:
                                 <br>
                                 <INPUT TYPE=&quot;text&quot; NAME=&quot;subject&quot; SIZE=&quot;30&quot;></INPUT><BR>
                                 
                                 Message:
                                 <br>
                                 <TEXTAREA NAME=&quot;body&quot; ROWS=&quot;10&quot; COLS=&quot;40&quot; WRAP=&quot;virtual&quot;></TEXTAREA><BR>
                                 
                                 <INPUT TYPE=&quot;submit&quot; VALUE=&quot;Send Message!&quot;></INPUT>
                             </FORM>

<%
end sub

sub send_email()
                             Set objCDOMail = Server.CreateObject(&quot;CDONTS.NewMail&quot;)
                                 
                             objCDOMail.From    = &quot;Visitor <Server@tplanet.com>&quot;
                             objCDOMail.To      = strTo
                             objCDOMail.Subject = strSubject
                             objCDOMail.Body    = strBody

                             objCDOMail.Cc         = &quot;user@domain.com;user@domain.com&quot;
                             
                             objCDOMail.Send
                             
                             Set objCDOMail = Nothing

                             Response.Write strResponse
                             End If
 
end sub
                        
 Function IsValidEmail(strEmail)
                             Dim bIsValid
                             bIsValid = True
                             
                             If Len(strEmail) < 5 Then
                                 bIsValid = False
                             Else
                                 If Instr(1, strEmail, &quot; &quot;) <> 0 Then
                                     bIsValid = False
                                 Else
                                     If InStr(1, strEmail, &quot;@&quot;, 1) < 2 Then
                                         bIsValid = False
                                     Else
                                         If InStrRev(strEmail, &quot;.&quot;) < InStr(1, strEmail, &quot;@&quot;, 1) + 2 Then
                                             bIsValid = False
                                         End If
                                     End If
                                 End If
                             End If

                             IsValidEmail = bIsValid
                         End Function
                         %>

Bastien

Any one have a techie job in Toronto, I need to work...being laid off sucks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top