Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Feedback Form 1

Status
Not open for further replies.

kebele

MIS
Jul 31, 2006
107
US
hi all,
I am working on this feedback form and I am entering the data to access database and then also send the result by e-mail. This way, if the email gets lost, there is still a record of the Feedback.
I think i can enter the data with out any problem but sending e-mail part is giving me a headache and I really appreciate one of you take a look at my code throw me some ideas. thank you

Imports System.Data.OleDb
Imports System.Net.Mail
Partial Class FeedBack
Inherits System.Web.UI.Page

Sub doInsert(ByVal Source As Object, ByVal E As EventArgs)

Dim conFeedBack As OleDbConnection
conFeedBack = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\FeedBack.mdb")

Dim MySQL As String = "Insert into feedback (CompanyName,ContactPerson,Address1,Address2,City, State,ZipCode,PhoneNumber, Email, Fax,Comment) " & _
"Values (@Office, @person,@Address1,@Address2,@City,@State,@Zip,@Phone,@Email,@Fax,@Comment)"

Dim Cmd As New OleDbCommand(MySQL, conFeedBack)
With Cmd.Parameters
.Add(New OleDbParameter("@Office", txtOffice.Text))
.Add(New OleDbParameter("@Person", txtPerson.Text))
.Add(New OleDbParameter("@Address1", txtAddress1.Text))
.Add(New OleDbParameter("@Address2", txtAddress2.Text))
.Add(New OleDbParameter("@City", txtCity.Text))
.Add(New OleDbParameter("@State", dpState.Text))
.Add(New OleDbParameter("@Zip", txtZip.Text))
.Add(New OleDbParameter("@Phone", txtPhone.Text))
.Add(New OleDbParameter("@Email", txtEmail.Text))
.Add(New OleDbParameter("@Fax", txtFax.Text))
.Add(New OleDbParameter("@Comment", txtComment.Text))
'.Add(New OleDbParameter("@dtEntered", DateTime.Now()))
End With
conFeedBack.Open()
cmd.ExecuteNonQuery()
lblFeed.Text = "Your inormation has been successfully received." & _
"We will get back to you as soon as possible"
conFeedBack.Close()
End Sub
Sub doEmail()
Dim sMsg As String
Dim sBody As String
sMsg = "Feedback has been sent to you." & vbcrlf & "The results are as follows:" & vbcrlf
sMsg += "Company Name : " & txtOffice.Text & vbCrLf
sMsg += "Contact Person : " & txtPerson.Text & vbCrLf
sMsg += "Address1 : " & txtAddress1.Text & vbCrLf
sMsg += "Address2 : " & txtAddress2.Text & vbCrLf
sMsg += "City : " & txtCity.Text & vbCrLf
sMsg += "State : " & dpState.Text & vbCrLf
sMsg += "Zip Code : " & txtZip.Text & vbCrLf
sMsg += "Phone Number : " & txtPhone.Text & vbCrLf
sMsg += "Fax : " & txtFax.Text & vbCrLf
sMsg += "E-mail : " & txtEmail.Text & vbCrLf

----------I am getting error msg below this line
Dim objEmail As New MailMessage
objEmail.To=Bid.Letting@dot.state.mn.us
objEmail.From = txtEmail.Text
objEmail.Subject = "You have Feedback"
objEmail.Body = sMsg
objEmail.BodyFormat = MailFormat.Text
SmtpMail.SmtpServer = "mail.Wherever.com"
SmtpMail.Send(objEmail)
End Sub



End Class
 
kebele,

In your code:
Code:
----------I am getting error msg below this line
Dim objEmail As New MailMessage
[b]objEmail.To=Bid.Letting@dot.state.mn.us
objEmail.From = txtEmail.Text[/b]
objEmail.Subject = "You have Feedback"
objEmail.Body = sMsg
objEmail.BodyFormat = MailFormat.Text
SmtpMail.SmtpServer = "mail.Wherever.com"
SmtpMail.Send(objEmail)
change the bolded lines to:
Code:
bjEmail.To = New MailAddress("Bid.Letting@dot.state.mn.us")
objEmail.From = New MailAddress(txtEmail.Text)
and see how that works.

Senior Qik III, ASP.Net, VB.Net ,SQL Programmer

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
** Do NOT feed Code Gremlins after midnight **
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
What error message?

Also, use a StringBuilder rather than a String.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
PsychoCoder thank you for reply and I changed both and I am still getting this error message on first line here is sayst property TO is read only.any clue on that?

objEmail.To = New MailAddress("Bid.Letting@dot.state.mn.us")
objEmail.From = New MailAddress(txtEmail.Text)
 
The error message seems to go away once i add this line
objEmail.To.Add(New MailAddress("Bid.Letting@dot.state.mn.us"))
but I am getting a different error messge.What to I need to do for SMTP hos to work properly.Do I need to add someting into the webconfig file? Please help
Thank you so much



The SMTP host was not specified.
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.InvalidOperationException: The SMTP host was not specified.

Source Error:


Line 54: objEmail.Body = sMsg
Line 55: Dim SmtpMail As New SmtpClient()
Line 56: SmtpMail.Send(objEmail)
Line 57:
Line 58: End Sub

 
kebele,

You need code like this somewhere:
Code:
  Dim Client As New Net.Mail.SmtpClient()
  Client.Host = "your_mail_server"
  Client.Send(oMail)
to replace these 2 lines of code:
Code:
  SmtpMail.SmtpServer = "mail.Wherever.com"
  SmtpMail.Send(objEmail)

You can also add a section like this to your web.config file:
Code:
<system.net>
  <mailSettings>
    <smtp>
      <network 
      host="relayServerHostname" 
      port="portNumber"
      userName="username"
      password="password" />
    </smtp>
  </mailSettings>
</system.net>

And you can have your SMTPClient use these credentials and you wont have the add the first block of code to your code behind page.

Hope this helps

Senior Qik III, ASP.Net, VB.Net ,SQL Programmer

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
** Do NOT feed Code Gremlins after midnight **
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
PsychoCoder thank you for your response and please bear with me as i learn this sending e-mail..I prefer to have all the info. in the webconfig file as you suggested above.My question is how or where can i find information on relayserverhost name? I think port number is 25 and also where can i find the userName and Password.Thank you for your patient and help.


<system.net>
<mailSettings>
<smtp>
<network
host="relayServerHostname"
port="portNumber"
userName="username"
password="password" />
</smtp>
</mailSettings>
</system.net>

 
kebele,

Replace relayServerHostname with you mail server

Senior Qik III, ASP.Net, VB.Net ,SQL Programmer

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
** Do NOT feed Code Gremlins after midnight **
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top