我创建了一个简单的联系表单...当我点击发送按钮时,我将信息提交给我
这是我在本地服务器上运行代码的问题。但它没有运行 在实时服务器上(Godaddy服务器)它提供了例外
以下是代码:
Imports System.IO
Imports System.Net.Mail
Partial Class Contact_Form_Demo
Inherits System.Web.UI.UserControl
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim fileName As String = Server.MapPath("~/App_Data/ContactForm.txt")
Dim mailBody As String = File.ReadAllText(fileName)
mailBody = mailBody.Replace("##Name##", TextBox1.Text)
mailBody = mailBody.Replace("##Email##", TextBox2.Text)
mailBody = mailBody.Replace("##HomePhone##", TextBox3.Text)
mailBody = mailBody.Replace("##BusinessPhone##", TextBox4.Text)
mailBody = mailBody.Replace("##Comments##", TextBox5.Text)
Dim mymessage As MailMessage = New MailMessage()
mymessage.Subject = "Response from web site"
mymessage.Body = mailBody
mymessage.From = New MailAddress("Email Here", "Tuhin Bhatt")
mymessage.To.Add(New MailAddress("My Email Here", "Tuhin Bhatt"))
Dim mysmtpclient As SmtpClient = New SmtpClient()
mysmtpclient.Send(mymessage)
End Sub
End Class
这是我在实时服务器上遇到的错误:
Server Error in '/' Application. A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 74.125.95.109:25 Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.Net.Sockets.SocketException: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 74.125.95.109:25 Source Error: Line 26: Line 27: Dim mysmtpclient As SmtpClient = New SmtpClient() Line 28: mysmtpclient.Send(mymessage) Line 29: End Sub Line 30: End Class
答案 0 :(得分:3)
您的托管环境不允许您使用Web.config中指定的设置访问SMTP服务器。如果您的web.config文件中没有<mailSettings>
部分,则表示您的应用程序正在尝试访问GoDaddy的machine.config文件指定的设置。很可能,您不允许访问该特定服务器和端口。
请在此处查看如何设置MailSettings部分。并为您管理的网站使用SMTP服务器的名称和密码。
答案 1 :(得分:2)
Dim mysmtpclient As SmtpClient = New SmtpClient()
除非您出于隐私原因而忽略它,否则您的SmtpClinet()会遗漏一些声明,即邮件服务器和端口。