'SMTP Email Works until triggering a 404 error in the middle of sending Mail

I have a table for email recipients imma database, and use the "select all" button from the gridview table as trigger to call the mail function. my iteration func to call the 'executeApprove' repeatedly described here :

            For Each row In gridApproval.Rows
                        chkApprove = CType(gridApproval.Rows(i).FindControl("chkApprove"), CheckBox)
                        If chkApprove.Checked Then
                            executeApprove(Right(lblTglProses.Text, 8), Left(gridApproval.Rows(i).Cells.Item(2).Text, 3), Session("role"), "APPROVE", Session("userID"), False)
                        End If
                        i = i + 1
                    Next
                Catch ex As Exception
                    ScriptManager.RegisterStartupScript(Me.UpdatePanel1, Me.GetType, "Message", "alert('Error : ' + '" & Replace(Replace(ex.Message.ToString, "'", ""), vbNewLine, "") & "');", True)
                End Try
                gridApproval.DataBind()
            End If

on my executeApprove :

Protected Sub executeApprove(ByVal tanggal As String, ByVal branch As String, ByVal role As String, ByVal status As String, ByVal user As String, ByVal isDone As Boolean)
    Dim Title As String
    Dim Body As String
    Try
        conn = run.connect(conn, "open")
        cmd = New SqlCommand("usp_status_trial", conn)
        cmd.CommandType = CommandType.StoredProcedure
        cmd.CommandTimeout = 0
        cmd.Parameters.Add("@date", SqlDbType.VarChar).Value = tanggal
        cmd.Parameters.Add("@branch", SqlDbType.VarChar).Value = branch
        cmd.Parameters.Add("@role", SqlDbType.VarChar).Value = role
        cmd.Parameters.Add("@status", SqlDbType.VarChar).Value = status
        cmd.Parameters.Add("@user", SqlDbType.VarChar).Value = user
        reader = cmd.ExecuteReader
        If reader.HasRows Then
            reader.Read()
            result = reader.Item(0).ToString
            ScriptManager.RegisterStartupScript(Me.UpdatePanel1, Me.GetType, "Message", "alert('" & result & "');", True)
            If result = "APPROVED" Then
                If Session("role") = "APP" Then
                    Title = "Title Email"
                    Body = "Body Email"
                    sendMultipleMail(Title, Body)
                End If
            ElseIf result = "UNAPPROVED" Then
                If Session("role") = "APP" Then
                    Title = "Title Email"
                    Body = "Body Email"
                    sendMultipleMail(Title, Body)
                End If
            End If

            If isDone Then
                Response.Redirect("~/dashboard.aspx?id=" + Request.QueryString("id"), True)
            End If

        End If
        conn = run.connect(conn, "close")
    Catch ex As Exception
        ScriptManager.RegisterStartupScript(Me.UpdatePanel1, Me.GetType, "Message", "alert('Error : ' + '" & Replace(Replace(ex.Message.ToString, "'", ""), vbNewLine, "") & "');", True)
    End Try
End Sub

and my sendMultipleMail :

Public Sub sendMultipleMail(ByVal subject As String, ByVal body As String)
    Dim dsMail As New DataSet
    Dim strQuery As New SqlCommand
    Dim SendFrom As MailAddress
    Dim SendTo As MailAddress
    Dim emailClient As SmtpClient
    Dim SMTP As String
    Dim mailFrom As String

    SMTP = getAppParam("SMTPserver")    'got the SMTP
    mailFrom = getMailSetting("mailFrom")
    strQuery.CommandText = "%'Query for select all the receiver'%"
    dsMail = RunQuery(strQuery)
    For Each rowMail In dsMail.Tables(0).Rows
        SendFrom = New MailAddress(mailFrom)
        SendTo = New MailAddress(rowMail("mail_address").ToString())

        Dim MyMessage As MailMessage = New MailMessage(SendFrom, SendTo)

        MyMessage.Subject = subject
        MyMessage.Body = body

        emailClient = New SmtpClient(SMTP)
        emailClient.Send(MyMessage)
    Next
End Sub

everything works just fine until a few minutes while sending the lot of email (in the middle of calling the func repeatedly), the IIS returning a strange 404 response.

POST http://localhost/myApp/approval?type=all&id=userid 500 (Internal Server Error) -- MicrosoftAjax.js:6

Uncaught TypeError: Cannot read properties of undefined (reading 'PRM_ServerError') at Sys.WebForms.PageRequestManager._createPageRequestManagerServerError (MicrosoftAjaxWebForms.js:6:11462) at Sys.WebForms.PageRequestManager._onFormSubmitCompleted (MicrosoftAjaxWebForms.js:6:25554) at Array. (MicrosoftAjax.js:6:307) at MicrosoftAjax.js:6:51370 at Sys.Net.WebRequest.completed (MicrosoftAjax.js:6:89678) at XMLHttpRequest._onReadyStateChange (MicrosoftAjax.js:6:84277)

am I made some mistakes?



Solution 1:[1]

Thank you for the answer. Error 404 appears just because the SMTP takes a lot of time to send a whole of email to the receiver. so i've been fixing them using

<security>
    <requestFiltering>
        <requestLimits maxAllowedContentLength="3000000000" />
    </requestFiltering>
</security>

inside .config file to increase the timeout.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Hananta Adhi