使用 ASP:Wizard Control 和 SMTPClient 的 ASP.net 3.5 网站不发送电子邮件
我在运行 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("[email protected]", "[email protected]")
Dim myFrom As New MailAddress("[email protected]")
Dim myTo As New MailAddress("[email protected]")
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
End Class
代码符合要求,没有错误。当加载到共享主机帐户时,页面将加载并且代码允许用户在向导中输入信息。但是,“完成”按钮不会触发最后一步。以下是向导最后一步的代码:
<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>
我无法确定是什么导致了这个问题。有人可以指导我找出可能的原因吗?
谢谢, 席德
I have a asp:Wizard control on a site running Framework 3.5. I acquired the settings from the web host and have entered them into the Web Configuration Utility. Here's the code behind file:
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("[email protected]", "[email protected]")
Dim myFrom As New MailAddress("[email protected]")
Dim myTo As New MailAddress("[email protected]")
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
End Class
The code complies with no error. When loaded onto the shared hosting account, the page loads and the code allows the user to enter information into the wizard. However, the Finish button does not fire the final step. Here's the code for the final wizard step:
<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>
I cannot determine what is cuasing this issue. Can someone direct me as to possible causes?
Thanks,
Sid
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否在代码中设置了断点来查看是否确实到达了发送邮件的代码?例如,我建议您至少在以下位置设置断点:
验证 FinishButtonClick 事件是否正在触发。
验证Sendmail代码是否被命中。
查看是否有异常发生。
此外,至少还有其他一些事情需要注意。
SMTP 服务器可能未配置或配置正确。
即使 SMTP 服务器配置正确,您也希望确保您的防火墙(或 ISP)不会阻止 SMTP 邮件的发送。
Have you set breakpoints within the code to see if the code to send mail is actually being reached? For example, I would suggest you set breakpoints at least at the following:
To verify the FinishButtonClick event is firing.
To verify the Sendmail code is being hit.
To see if any exception is occurring.
Also, there are at least a couple of other things to look out for.
The SMTP server may not be configured or properly configured.
Even if the SMTP Server is properly configured, you want to make sure your firewall (or your ISPs) is not blocking the sending of SMTP mail.