Page view counter

[How Do I:] Create a "Contact Us" Page?

Please install Silverlight or click download to watch video locally.

Build a web page to collect information from the user with the Wizard control, validate that information, and use the System.Net.Mail classes to send a confirmation email message.

Duration: 13 minutes, 59 seconds

Date: 24 January 2006

Watch    Video   |   Download    Video   |   VB Code    C# Code

Video downloads: WMV  |  Zune  |  iPod  |  PSP  |  MPEG-4  |  3GP

Audio downloads: AAC  |  WMA  |  MPEG-4  |  MPEG-3  |  MPEG-2

Comments : 37

Leave a Comment

huuson : On April 14, 2008 2:01 PM said:

In this video, i see you can send email in localhost.

private void SendMail(string from, string body)

   {

       string mailServerName = "SMTP.MyDomain.com";

       MailMessage message = new MailMessage(from, "scott@vertigosoftware.com", "feedback", body);

       SmtpClient mailClient = new SmtpClient();

       mailClient.Host = mailServerName;

       mailClient.Send(message);

       message.Dispose();

   }

On my computer,How do I rewrite that code ?

Matt3.5 : On April 16, 2008 5:35 AM said:

I suggest you visit a site called 4guysfromrolla.com

There you will find several, well written articles, showing you in detail how to send basic - complex emails using the system.net.mail class. The author is Scott Mitchell, a well respected MVP.

cemakpolat : On April 21, 2008 4:00 AM said:

i can't download this video and the others,also i can't watch it.

Diego Vieira : On May 23, 2008 3:49 PM said:

cemakpolat, you just have to click the "Download the video" link and save it to your desktop. To watch the video you can download a codec pack from the internet. Just do a search for "codec pack".

Diego Vieira : On May 26, 2008 1:13 PM said:

Argh.. zip is corrupted.. please fix

download.microsoft.com/.../hilo_contact_final.zip

cinstress2 : On June 01, 2008 3:36 PM said:

How do you get all the data to email.

the code from the example says

Protected Sub Wizard1_FinishButtonClick(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.WizardNavigationEventArgs) Handles Wizard1.FinishButtonClick

       SendMail(txtEmail.Text, txtComments.Text)

   End Sub

How do you get the ratings and person's name to show up.

I tried adding these in the SendMail area... but it only allows two items.  How do you get all the fields to appear in the email that is sent to you?

mikaelKP : On June 04, 2008 12:19 PM said:

Use

Protected Sub Wizard1_FinishButtonClick(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.WizardNavigationEventArgs) Handles Wizard1.FinishButtonClick

      SendMail(txtEmail.Text, txtComments.Text, txtName.Text)

  End Sub

You can fill all the txtSomthing.Text as you want

I have no problem with this method:)

cburts : On June 22, 2008 5:53 AM said:

Hello,

I copied the code and config file into a new Asp.Net 3.5 website I created in VB Web Developer Express 2008 and I get an Operation has timed out error after I click the Finish button (takes a long time).  Source error: Line 16 mailClient.Send(message)

Stack Trace:

[SmtpException: The operation has timed out.]

  System.Net.Mail.SmtpClient.Send(MailMessage message) +1948

  _Default.SendMail(String from, String body) in C:\Users\websitepath\Default.aspx.vb:16

  _Default.Wizard1_FinishButtonClick(Object sender, WizardNavigationEventArgs e) in C:\Users\websitepath\Default.aspx.vb:8

  System.Web.UI.WebControls.Wizard.OnFinishButtonClick(Wizard NavigationEventArgs e) +105

  System.Web.UI.WebControls.Wizard.OnBubbleEvent(Object source, EventArgs e) +693

  System.Web.UI.WebControls.WizardChildTable.OnBubbleEvent(Ob ject source, EventArgs args) +17

  System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +35

  System.Web.UI.WebControls.Button.OnCommand(CommandEventArgs e) +115

  System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +163

  System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEve ntHandler.RaisePostBackEvent(String eventArgument) +7

  System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11

  System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33

  System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1746

David007 : On June 22, 2008 8:13 AM said:

Hi,

I did this with VS2005 and used "localhost". I moved it to 2003 server and works great. I would like to populate the "Summary" section. I've never used the wizzard before.

Please show me how to populate 1 label and I will take it from there !

Thank You in Advance

David007

PS- Love the videos !

David007 : On June 22, 2008 8:13 AM said:

Hi,

I did this with VS2005 and used "localhost". I moved it to 2003 server and works great. I would like to populate the "Summary" section. I've never used the wizzard before.

Please show me how to populate 1 label and I will take it from there !

Thank You in Advance

David007

PS- Love the videos !

David007 : On June 22, 2008 8:14 AM said:

Hi,

I did this with VS2005 and used "localhost". I moved it to 2003 server and works great. I would like to populate the "Summary" section. I've never used the wizzard before.

Please show me how to populate 1 label and I will take it from there !

Thank You in Advance

dollu : On July 14, 2008 3:16 PM said:

I am getting following error while coding the last page.. Can you help me understand where am I wrong??

The rest of the code is working finr, since I checked it after very next step..

_________________________________________________________

Compilation Error

Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: BC30203: Identifier expected.

Source Error:

Line 35:     Private Sub SendMail(ByVal from As String, ByVal body As String)

Line 36:         Dim mailServerName As String = "mail.yahoo.com"

Line 37: Dim message As MailMessage = New MailMessage(from. "hi_dollu@yahoo.com". "feedback".body)

Line 38:         Dim mailClient As SmtpClient = New SmtpClient

Line 39:

brooxy28 : On July 14, 2008 9:59 PM said:

Aboriginals.

nickchen88 : On July 29, 2008 7:00 AM said:

How do i populate the the summary section. its not show in the video...pls help

cv_vikram : On August 08, 2008 11:10 AM said:

Very good video...thanks

johncarerra : On August 26, 2008 8:26 PM said:

why i see blank black screen after you show you got an email..

btw thanx hope can get full version of it

tmorton : On August 27, 2008 2:23 PM said:

The .zip file does not seem corrupted to me.  I was able to download it, extract the .wmv file, and watch it in Windows Media Player 11.

khmohsin : On September 18, 2008 9:05 AM said:

How do you get the ratings ,person's name and other custom fields information show up.

I am unable to add them

nivlemnohj : On September 29, 2008 6:18 PM said:

Hi!

How to authenticate username and password with specific smtp port?

tnx

samuel24 : On September 30, 2008 7:11 AM said:

good thanx @@@@@@@@

great job!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

rajar32 : On October 24, 2008 5:48 AM said:

awesome....

djibril_chimere_DIAW : On October 28, 2008 6:14 AM said:

Thanks! Jërëjëf!

klakieros : On November 14, 2008 5:04 AM said:

Guys,

Great video - very helpful.

I've got one problem, the javascript in the code is not working with my browser... I even copied the code into new project and tried - nothing. I have checked that my browser is javascript enabled. It's IE 7.0.5730.13

Any ideas?

dpschwartz : On November 23, 2008 3:49 PM said:

Great video - but like some other respondents, I'd like to be able to include the text box entries (more than 2) and several checkboxes in the email. I started down the path of creating a giant string something like this:

Dim MyBody As String

MyBody = tbFirstName.Text & tbLastName.Text & vbCrLF &

tbEmail.Text & vbCrLF &

cbReceiveEmail.whatproperty?? ...

msgMail.Body = MyBody

But, I get the error on each of these textboxes:

"Reference to a non-shared member requires an object reference"

and from there I am totally lost. How did everyone solve this problem of including many textboxes and checkboxes in the email? Am I anywhere near on the right track?

Thanks.

Nezdet : On December 05, 2008 1:38 AM said:

There is one bad thing about wizard.. It gets really slow when I have large steps..

Is there some way to make this faster???

aesaif : On December 16, 2008 4:54 PM said:

i cant dowenload or watch the video .why??!!

voldy2 : On January 18, 2009 11:17 AM said:

I have uploaded the VB code in a live environment but when I upload the C# I'm getting no error and no email received. All my smtp setting are exact in both code files. Any ideas? Cheers.

fusion95624 : On February 05, 2009 6:58 PM said:

just like some others, i would like to know how can i send more than 2 input entries from the user. i have couple of check box, dropdown list and text box. please help...!!!!

ali waris21 : On February 12, 2009 12:11 PM said:

The remote name could not be resolved: 'exchange01.hotmail.com'

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.WebException: The remote name could not be resolved: 'exchange01.hotmail.com'

Source Error:

The source code that generated this unhandled exception can only be shown when compiled in debug mode. To enable this, please follow one of the below steps, then request the URL:

1. Add a "Debug=true" directive at the top of the file that generated the error. Example:

 <%@ Page Language="C#" Debug="true" %>

or:

2) Add the following section to the configuration file of your application:

<configuration>

  <system.web>

      <compilation debug="true"/>

  </system.web>

</configuration>

Note that this second technique will cause all files within a given application to be compiled in debug mode. The first technique will cause only that particular file to be compiled in debug mode.

Important: Running applications in debug mode does incur a memory/performance overhead. You should make sure that an application has debugging disabled before deploying into production scenario.  

Stack Trace:

[WebException: The remote name could not be resolved: 'exchange01.hotmail.com']

  System.Net.ServicePoint.GetConnection(PooledStream PooledStream, Object owner, Boolean async, IPAddress& address, Socket& abortSocket, Socket& abortSocket6, Int32 timeout) +414

  System.Net.PooledStream.Activate(Object owningObject, Boolean async, Int32 timeout, GeneralAsyncDelegate asyncCallback) +191

  System.Net.PooledStream.Activate(Object owningObject, GeneralAsyncDelegate asyncCallback) +21

  System.Net.ConnectionPool.GetConnection(Object owningObject, GeneralAsyncDelegate asyncCallback, Int32 creationTimeout) +329

  System.Net.Mail.SmtpConnection.GetConnection(String host, Int32 port) +188

  System.Net.Mail.SmtpTransport.GetConnection(String host, Int32 port) +265

  System.Net.Mail.SmtpClient.GetConnection() +43

  System.Net.Mail.SmtpClient.Send(MailMessage message) +1441

[SmtpException: Failure sending mail.]

  System.Net.Mail.SmtpClient.Send(MailMessage message) +2039

  _Default.sendmail(String from, String body) +92

  _Default.Wizard1_FinishButtonClick(Object sender, WizardNavigationEventArgs e) +58

  System.Web.UI.WebControls.Wizard.OnFinishButtonClick(Wizard NavigationEventArgs e) +75

  System.Web.UI.WebControls.Wizard.OnBubbleEvent(Object source, EventArgs e) +620

  System.Web.UI.WebControls.WizardChildTable.OnBubbleEvent(Ob ject source, EventArgs args) +17

  System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +35

  System.Web.UI.WebControls.Button.OnCommand(CommandEventArgs e) +86

  System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +155

  System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEve ntHandler.RaisePostBackEvent(String eventArgument) +7

  System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11

  System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33

  System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +4919

bohunt : On February 13, 2009 12:36 PM said:

Very useful, thanks!

Soha.Jawabreh : On February 13, 2009 11:29 PM said:

thanks

haseeb90 : On March 05, 2009 11:49 PM said:

Hi Friends I need ur help

how do u get the messege through this tutorial help

when i make any change in coding like i have made

Private Sub SendMail(ByVal from As String, ByVal body As String)

Dim mailServerName As String = "smtp.gmail.com"

Dim message As MailMessage = New MailMessage(from, "haseeb.06@gmail.com", "feedback", body)

Dim mailClient As SmtpClient = New SmtpClient

it will not working plzz help i need ur help friends i am very thankfull to u

Server Error in '/Contact_VB' 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

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

Source Error:

The source code that generated this unhandled exception can only be shown when compiled in debug mode. To enable this, please follow one of the below steps, then request the URL:

1. Add a "Debug=true" directive at the top of the file that generated the error. Example:

<%@ Page Language="C#" Debug="true" %>

or:

2) Add the following section to the configuration file of your application:

<configuration>

<system.web>

<compilation debug="true"/>

</system.web>

</configuration>

Note that this second technique will cause all files within a given application to be compiled in debug mode. The first technique will cause only that particular file to be compiled in debug mode.

Important: Running applications in debug mode does incur a memory/performance overhead. You should make sure that an application has debugging disabled before deploying into production scenario.

Stack Trace:

[SocketException (0x274c): 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]

System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress) +369

System.Net.Sockets.Socket.InternalConnect(EndPoint remoteEP) +35

System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Int32 timeout, Exception& exception) +421

[WebException: Unable to connect to the remote server]

System.Net.ServicePoint.GetConnection(PooledStream PooledStream, Object owner, Boolean async, IPAddress& address, Socket& abortSocket, Socket& abortSocket6, Int32 timeout) +413

System.Net.PooledStream.Activate(Object owningObject, Boolean async, Int32 timeout, GeneralAsyncDelegate asyncCallback) +191

System.Net.PooledStream.Activate(Object owningObject, GeneralAsyncDelegate asyncCallback) +21

System.Net.ConnectionPool.GetConnection(Object owningObject, GeneralAsyncDelegate asyncCallback, Int32 creationTimeout) +329

System.Net.Mail.SmtpConnection.GetConnection(String host, Int32 port) +188

System.Net.Mail.SmtpTransport.GetConnection(String host, Int32 port) +265

System.Net.Mail.SmtpClient.GetConnection() +43

System.Net.Mail.SmtpClient.Send(MailMessage message) +1441

[SmtpException: Failure sending mail.]

System.Net.Mail.SmtpClient.Send(MailMessage message) +2039

_Default.SendMail(String from, String body) +92

_Default.Wizard1_FinishButtonClick(Object sender, WizardNavigationEventArgs e) +58

System.Web.UI.WebControls.Wizard.OnFinishButtonClick(WizardNavigationEventArgs e) +75

System.Web.UI.WebControls.Wizard.OnBubbleEvent(Object source, EventArgs e) +620

System.Web.UI.WebControls.WizardChildTable.OnBubbleEvent(Object source, EventArgs args) +17

System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +35

System.Web.UI.WebControls.Button.OnCommand(CommandEventArgs e) +86

System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +155

System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +7

System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11

System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33

System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +4919

--------------------------------------------------------------------------------

Version Information: Microsoft .NET Framework Version:2.0.50727.42; ASP.NET Version:2.0.50727.42

haseeb90 : On March 06, 2009 2:20 PM said:

plzz i need help

give me the answer what the problem with coding or any other plz reply

m waiting its urgent

cemelek : On March 24, 2009 2:44 AM said:

when i click finish button i am receving following error message:

mailClient.Send(message)

The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.0 Must issue a STARTTLS command first. 5sm1618044eyf.2

any suggestion?

i am using gmail. smtp is smtp.gmail.com and port is 465.

dropkic : On March 25, 2009 8:22 PM said:

Here is my contact page code-behind with a Multiview and view controls:

Imports System.Net.Mail

Partial Class subpages_Contact

Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

If Not IsPostBack Then

ContactMultiView.SetActiveView(FormView)

End If

End Sub

Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click

ContactMultiView.SetActiveView(SuccessView)

Dim objMail As New MailMessage()

objMail.From = New MailAddress("webmasterjoe@josetamez.com")

objMail.To.Add("webmasterjoe@josetamez.com")

objMail.Subject = "Contact Form"

objMail.Body = "Company Name: " & txtCompanyName.Text & vbCrLf & _

"Contact Name: " & txtContactName.Text & vbCrLf & _

"Email Address: " & txtEmail.Text & vbCrLf & _

"City: " & txtCity.Text & vbCrLf & _

"State: " & ddState.Text & vbCrLf & _

"User Comments: " & txtComments.Text

objMail.IsBodyHtml = True

objMail.Subject = "Contact Form"

objMail.Body = "<html><head><title>Contact Form</title></head><body>" & _

"

<b>The following is the form submitted from your web site:</b>:

" & _

"

<b>Company Name :</b> " & txtCompanyName.Text + "

" & _

"

<b>Contact Name :</b> " & txtContactName.Text + "

" & _

"

<b>Email Address :</b> " & txtEmail.Text + "

" & _

"

<b>City :</b> " & txtCity.Text + "

" & _

"

<b>State :</b> " & ddState.Text + "

" & _

"

<b>User Comments</b> : " & txtComments.Text + "

" & _

"

Sent At: " & System.DateTime.Now + "

" & _

"</body></html>"

Dim smtp As New SmtpClient("mail.josetamez.com")

smtp.Send(objMail)

End Sub

Protected Sub btnSub_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSub.Click

ContactMultiView.SetActiveView(ConfirmView)

lblCompanyName.Text = System.Web.HttpUtility.HtmlAttributeEncode(txtCompanyName.Text)

lblContactName.Text = System.Web.HttpUtility.HtmlAttributeEncode(txtContactName.Text)

lblCity.Text = System.Web.HttpUtility.HtmlAttributeEncode(txtCity.Text)

lblState.Text = System.Web.HttpUtility.HtmlAttributeEncode(ddState.SelectedValue)

lblComments.Text = System.Web.HttpUtility.HtmlAttributeEncode(txtComments.Text)

End Sub

Protected Sub btnEdit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnEdit.Click

ContactMultiView.SetActiveView(FormView)

End Sub

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click

txtCompanyName.Text = ""

txtContactName.Text = ""

txtEmail.Text = ""

txtCity.Text = ""

txtComments.Text = ""

End Sub

End Class

johnbangla : On April 05, 2009 1:26 AM said:

MANY PEOPLE ARE SAYING THAT THEY CAN'T WATCH VIDEO.THE SIMPLE SOLUTON IS THAT DOWNLOAD "STORM CODEC" EVERYTHING WOULD BE FINE.

JOHN

FROM BANGLADESH(JOHN_BANGLA1@YAHOO.COM)

nishanththumma : On May 01, 2009 12:28 AM said:

private void SendMail(string from, string body)

{

string mailServerName = "smtp.gmail.com";

MailMessage message = new MailMessage(from, "thummanishanth@gmail.com", "feedback", body);

SmtpClient mailClient = new SmtpClient();

mailClient.Host = mailServerName;

mailClient.Send(message);// it shows some error here

message.Dispose();

}

can u plz explain wat must the problem

anyone C# fellows

Leave a Comment

You must be logged in to leave a comment. Click here to log in.

Microsoft Communities