2011-07-07 77 views
1

我创建了一个简单的联系表单......那提交资料给我,当我在发送键Asp.net网站电子邮件错误

点击这里是我的代码问题上运行本地好吗服务器。不过,这并不一个活的服务器上运行 (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

什么是您的smtp客户端详细信息? – gandil

回答

3

您的托管环境不允许您使用Web.config中指定的设置访问SMTP服务器。如果您的web.config文件中没有<mailSettings>部分,则意味着您的应用程序正试图访问由GoDaddy的machine.config文件指定的设置。很可能,您不允许访问特定的服务器和端口。

看看如何在这里设置你的MailSettings部分。并使用名称和密码到您正在管理的网站的SMTP服务器。

+0

我已经在我的Web.config中设置了部分。我还指定了Smtp服务器名称,它是google ...还有我的用户名和密码,并将enablessl属性设置为True ...是因为Godaddy限制了我。我必须使用他们的电子邮件服务器.... ????? –

2
Dim mysmtpclient As SmtpClient = New SmtpClient() 

除非您因隐私原因而忽略它,否则您的SmtpClinet()缺少一些属性,即邮件服务器和端口。