0

我在运行 Framework 3.5 的站点上有一个 asp:Wizard 控件。我从 Web 主机获取设置并将它们输入到 Web 配置实用程序中。这是文件背后的代码:

Protected Sub Wizard1_FinishButtonClick(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.WizardNavigationEventArgs) Handles Wizard1.FinishButtonClick
    Dim mySMTPClient As New SmtpClient()
    Dim sb As New StringBuilder
    Dim myMail As New MailMessage("webmaster@mydomain.com", "user@mydomain.com")
    Dim myFrom As New MailAddress("webmaster@mydomain.com")
    Dim myTo As New MailAddress("user@anotherdomain.com")
    myMail.BodyEncoding = System.Text.Encoding.UTF8
    myMail.IsBodyHtml = False
    myMail.To.Add(myTo)
    myMail.Subject = "Request for Information"
    sb.Append("Contact Name: ")
    sb.Append(txtcontactname.Text)
    sb.Append("<br/>Phone Number: ")
    sb.Append(txtcontactphone.Text)
    sb.Append("<br/>Employer Name: ")
    sb.Append(txtemployername.Text)
    sb.Append("<br/>City: ")
    sb.Append(txtcity.Text)
    sb.Append("<br/>State: ")
    sb.Append(cmbstate.Text)
    sb.Append("<br/>Zip: ")
    sb.Append(txtzip.Text)
    sb.Append("<br/>Other Location: ")
    sb.Append(txtotherloc.Text)
    sb.Append("<br/>Nature of Business: ")
    sb.Append(txtbusnat.Text)
    sb.Append("<br/>Eligible Employees: ")
    sb.Append(txteligemps.Text)
    sb.Append("<br/>Average Employee Turnover Per Year: ")
    sb.Append(txtempturnover.Text)
    sb.Append("<br/>Broker Name: ")
    sb.Append(txtbrokername.Text)
    sb.Append("<br/>Broker Email: ")
    sb.Append(txtbrokeremail.Text)
    sb.Append("<br/>Proposed Effective Date: ")
    sb.Append(txteffdate.SelectedDate)
    sb.Append("<br/>Limited Benefit Medical Plans: ")
    For Each item As ListItem In chkmedplans.Items
        If (item.Selected) Then
            sb.Append(item.Text)
            sb.Append(" ")
        End If
    Next
    sb.Append("<br/>Voluntary Products/Services: ")
    For Each item As ListItem In chkvolserv.Items
        If (item.Selected) Then
            sb.Append(item.Text)
            sb.Append(" ")
        End If
    Next
    sb.Append("<br/>Employer Paid Products/Services: ")
    For Each item As ListItem In chkempserv.Items
        If (item.Selected) Then
            sb.Append(item.Text)
            sb.Append(" ")
        End If
    Next
    sb.Append("<br/>Preferred Benefit Enrollment Program(s): ")
    For Each item As ListItem In chkenrolprog.Items
        If (item.Selected) Then
            sb.Append(item.Text)
            sb.Append(" ")
        End If
    Next
    sb.Append("<br/>Comments: ")
    sb.Append(txtcomments.Text)
    myMail.Body = sb.ToString()
    Try
        mySMTPClient.Send(myMail)
    Catch ex As Exception
        Dim ex2 As Exception = ex
        Dim errorMessage As String = String.Empty
        While Not (ex2 Is Nothing)
            errorMessage += ex2.ToString()
            ex2 = ex2.InnerException
        End While
        Response.Write(errorMessage)
    End Try
End Sub

结束类

代码符合没有错误。当加载到共享主机帐户时,页面加载并且代码允许用户在向导中输入信息。但是,“完成”按钮不会触发最后一步。这是最后一个向导步骤的代码:

<asp:WizardStep ID="WizardStep4" runat="server" StepType="Complete" Title="Complete">
        Thank you for your inquiry.  A member of our staff will contact you regarding your request.</asp:WizardStep>

我无法确定是什么导致了这个问题。有人可以指导我了解可能的原因吗?

谢谢, 席德

4

1 回答 1

1

您是否在代码中设置了断点以查看发送邮件的代码是否实际到达?例如,我建议您至少在以下位置设置断点:

验证 FinishButtonClick 事件是否正在触发。

Dim mySMTPClient As New SmtpClient()

验证 Sendmail 代码是否被击中。

mySMTPClient.Send(myMail)

查看是否发生任何异常。

Dim ex2 As Exception = ex

此外,至少还有一些其他的事情需要注意。

  1. SMTP 服务器可能未配置或未正确配置。

  2. 即使正确配置了 SMTP 服务器,您也需要确保您的防火墙(或您的 ISP)没有阻止 SMTP 邮件的发送。

于 2009-09-13T21:08:05.983 回答