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:
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 " _
& "(UserID <= " & txtToUserID.Text.ToString & ") " _
& "order by UserID;"
SqlConnection1.ConnectionString = ConfigurationSettings.AppSettings("DBConnREMOTE")
Try
SqlConnection1.Open()
myreader = SqlCommand1.ExecuteReader(CommandBehavior.CloseConnection)
While myreader.Read
SendEmail(myreader("Email"))
End While
myreader.Close()
Catch objException as Exception
litMessage.Text += "Error occurred while trying to retrieve Email addresses from DB"
litMessage.Text += "<ul><li>Message: " & objException.Message & "</li>"
litMessage.Text += "<li>Source: " & objException.Source & "</li>"
litMessage.Text += "<li>TargetSite: " & objException.TargetSite.Name & "</li></ul>"
End Try
End Sub
Private Sub SendEmail(sTo as String)
On Error GoTo Badplace
'SmtpMail.SmtpServer = "mail.servername.com"
SmtpMail.Send(txtFrom.Text, sTo, txtSubject.Text, txtMessage.Text)
intEmailsSentCounter += 1
Exit Sub
Badplace:
litMessage.Text += "<br />" & sTo & " - Error: " & Err.Number & " - " & Err.Description
resume Next
End Sub