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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Request Timed Out - sending 50 emails 1

Status
Not open for further replies.

organicg

Programmer
Oct 21, 2002
151
US
I am trying to send out a bulk email from a webpage...to opt-in users, not to just anyone. I am getting 'Request Timed Out' somtimes.

I think the problem happens if there's a problem sending one of the emails because I successfully sent 60 emails, 20 to each of 3 addresses, that were all my own emails addresses, and all messages were received, and no ASP.NET error. But I get the error when I send the email to real users.
For one, I don't understand why the error isn't trapped since I have error handling in both procedures I call. I get the ASP.NET error page, not my custom error label. Here's the code:

Code:
    Private Sub Email_All_Users
        Dim myreader As SqlClient.SqlDataReader
        
        SqlCommand1.CommandText = "SELECT Email " _
                    & "FROM Users " _
                    & "WHERE (ReceiveEmails = 1) " _
                    & "AND (Active = 1) AND " _
                    & "(UserID >= " & txtFromUserID.Text.ToString & ") AND " _
                    & &quot;(UserID <= &quot; & txtToUserID.Text.ToString & &quot;) &quot; _
                    & &quot;order by UserID;&quot;

        SqlConnection1.ConnectionString = ConfigurationSettings.AppSettings(&quot;DBConnREMOTE&quot;)
        
        Try
            SqlConnection1.Open()

            myreader = SqlCommand1.ExecuteReader(CommandBehavior.CloseConnection)

            While myreader.Read
                SendEmail(myreader(&quot;Email&quot;))
            End While

            myreader.Close()

        Catch objException as Exception
            litMessage.Text += &quot;Error occurred while trying to retrieve Email addresses from DB&quot;
            litMessage.Text += &quot;<ul><li>Message: &quot; & objException.Message & &quot;</li>&quot;
            litMessage.Text += &quot;<li>Source: &quot; & objException.Source & &quot;</li>&quot;
            litMessage.Text += &quot;<li>TargetSite: &quot; & objException.TargetSite.Name  & &quot;</li></ul>&quot;
        End Try

    End Sub

    Private Sub SendEmail(sTo as String)
        
        On Error GoTo Badplace
            'SmtpMail.SmtpServer = &quot;mail.servername.com&quot;
            SmtpMail.Send(txtFrom.Text, sTo, txtSubject.Text, txtMessage.Text)
            intEmailsSentCounter += 1
        Exit Sub
        Badplace:
            litMessage.Text += &quot;<br />&quot; & sTo & &quot; - Error: &quot; & Err.Number & &quot; - &quot; & Err.Description 
        resume Next

    End Sub
 
For starters, try cleansing out the &quot;On Error Goto...&quot; statement and use Try/Catch blocks. That may catch your error if it is in your Sendmail function.

Neil Konitzer
Freisoft
 
I used &quot;On Error&quot; within the sub SendEmail so that if any email failed to send, control would return to the loop and the next emails would still try to be sent. Try/Catch cannot Resume Next from what I understand.

What I've found out is that sending mail this way waits for a response that the mail was sent, however, it may be in a queue that takes...who knows how long...for the email to be sent. I still don't understand why the Time Out isn't trapped, though, by one of the two error handlers. Do you know?

I think a better solution is to use a 3rd party component(supported by my web host) like ASPEmail(I think) that doesn't wait for a response. It puts the email in a queue and moves on. I have not tried to use it yet. I'm open to a solution that just uses SMTPMail object, though
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top