1

I Have Created a Simple Contact Form... That submits the information to me When i click on the send button

Here is the Problem that i have the code runs alright on the local server. But it does not run on a live server(Godaddy server) It Gives Exception

Here is the code:

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

This is the Error I get on live server:

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
1
  • what is your smtp client details?
    – gandil
    Jul 7, 2011 at 18:37

2 Answers 2

3

Your hosted environment does not allow you access to the SMTP Server with the settings specified in your Web.config. If you don't have a <mailSettings> section in your web.config file, that means that your application is attempting to access the settings specified by GoDaddy's machine.config file. And very likely, you're not allowed access to that particular server and port.

Take a look at how to set up your MailSettings section here. And use a name and password to the SMTP server for the website you're administering.

1
  • I have already setup the <mailsettings> Section in my Web.config. I have also specified Smtp server name which is google... And also my username and password and set enablessl attribute to True... is it because Godaddy is restricting me. Do i have to use their email server....????? Jul 9, 2011 at 5:46
2
Dim mysmtpclient As SmtpClient = New SmtpClient() 

Unless you are omitting it for privacy reasons, your SmtpClinet() is missing some arquments, namely the mail server and ports.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.