how to send email with asp.net with c #(FeedBack Form)
<p>I'm trying to create a feedback form.
Before that i was trying to make an email application but I could'nt get how to do that.</p>

<p>I found some code on the net.
I understood the code but was not able to resolve the problem.</p>

<p>my default.aspx page contain the following code</p>

<pre><code>&lt;%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %&gt;

&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"&gt;

&lt;html xmlns="http://www.w3.org/1999/xhtml" &gt;
&lt;head runat="server"&gt;
    &lt;title&gt;Send Email by .Net 2.0&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
    &lt;form id="form1" runat="server"&gt;
    &lt;div&gt;
        &lt;h2 style="background-color:Brown; color:Wheat; font-family:Verdana; font-size:14px" align=center&gt;Please enter the following requested 
                information below to send us your comments.&lt;/h2&gt;
            &lt;table align=center&gt;
                &lt;tr&gt;
                    &lt;td style="height: 26px"&gt;&lt;span style="font-family:Verdana; font-size:12px; font-weight:bold;color:Brown;"&gt;Your Name:&lt;/span&gt;&lt;/td&gt;
                    &lt;td style="height: 26px"&gt;&lt;asp:textbox id="txtName" Width="241" Runat="server"&gt;&lt;/asp:textbox&gt;&lt;/td&gt;
                &lt;/tr&gt;
                &lt;tr&gt;
                    &lt;td&gt;&lt;span style="font-family:Verdana; font-size:12px; font-weight:bold;color:Brown;"&gt;Your Email Address:&lt;/span&gt;&lt;/td&gt;
                    &lt;td&gt;&lt;asp:textbox id="txtEmail" Width="241" Runat="server"&gt;&lt;/asp:textbox&gt;&lt;/td&gt;
                &lt;/tr&gt;
                &lt;tr&gt;
                    &lt;td colSpan="2" &gt;&lt;span style="font-family:Verdana; font-size:12px; font-weight:bold; color:Brown;"&gt;Your Comment:&lt;/span&gt;&lt;/td&gt;
                &lt;/tr&gt;
                &lt;tr&gt;
                    &lt;td align="center" colSpan="2" width=100%&gt;&lt;asp:textbox id="txtMessage" Width="100%" Runat="server" Height="99" TextMode="MultiLine" MaxLength="400"&gt;&lt;/asp:textbox&gt;&lt;/td&gt;
                &lt;/tr&gt;
                &lt;tr&gt;
                    &lt;td colSpan="2"&gt;&amp;nbsp;&lt;/td&gt;
                &lt;/tr&gt;
                &lt;tr&gt;
                    &lt;td align=center&gt;&lt;asp:button id="btnSendmail" Runat="server" Text="Send Mail" OnClick="btnSendmail_Click"&gt;&lt;/asp:button&gt;&lt;/td&gt;
                    &lt;td align=center&gt;&lt;asp:button id="btnReset" Runat="server" Text="Reset" OnClick="btnReset_Click"&gt;&lt;/asp:button&gt;&lt;/td&gt;
                &lt;/tr&gt;
                &lt;tr&gt;
                    &lt;td colSpan="2"&gt;&lt;asp:label id="lblStatus" Runat="server" EnableViewState="False"&gt;&lt;/asp:label&gt;&lt;/td&gt;
                &lt;/tr&gt;
            &lt;/table&gt;
    &lt;/div&gt;
    &lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;
</code></pre>

<p>my code-behind for default.aspx</p>

<pre><code>using System;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Net.Mail;

public partial class _Default : System.Web.UI.Page 
{
    #region  "Send email"
    protected void btnSendmail_Click(object sender, EventArgs e)
    {
        // System.Web.Mail.SmtpMail.SmtpServer is obsolete in 2.0
        // System.Net.Mail.SmtpClient is the alternate class for this in 2.0
        SmtpClient smtpClient = new SmtpClient();
        MailMessage message = new MailMessage();

        try
        {
            MailAddress fromAddress = new MailAddress(txtEmail.Text, txtName.Text);

            // You can specify the host name or ipaddress of your server
            // Default in IIS will be localhost 
            smtpClient.Host = "localhost";

            //Default port will be 25
            smtpClient.Port = 1159;

            //From address will be given as a MailAddress Object
            message.From = fromAddress;

            // To address collection of MailAddress
            message.To.Add("admin1@yoursite.com");
            message.Subject = "Feedback";

            // CC and BCC optional
            // MailAddressCollection class is used to send the email to various users
            // You can specify Address as new MailAddress("admin1@yoursite.com")
            message.CC.Add("admin1@yoursite.com");
            message.CC.Add("admin2@yoursite.com");

            // You can specify Address directly as string
            message.Bcc.Add(new MailAddress("admin3@yoursite.com"));
            message.Bcc.Add(new MailAddress("admin4@yoursite.com"));

            //Body can be Html or text format
            //Specify true if it  is html message
            message.IsBodyHtml = false;

            // Message body content
            message.Body = txtMessage.Text;

            // Send SMTP mail
            smtpClient.Send(message);

            lblStatus.Text = "Email successfully sent.";
        }
        catch (Exception ex)
        {
            lblStatus.Text = "Send Email Failed.&lt;br&gt;" + ex.Message;
        }
    }
    #endregion

    #region "Reset"
    protected void btnReset_Click(object sender, EventArgs e)
    {
        txtName.Text = "";
        txtMessage.Text = "";
        txtEmail.Text = "";
    }
    #endregion
}
</code></pre>

<p>i m getting the error here</p>

<pre><code> // Send SMTP mail
 smtpClient.Send(message);
</code></pre>

<p>i dont know how to correct it.
my port no is 3168
i had tried to replace it.
but unable to resolve </p>

<p>the catch portion is getting "Failure sending Mail"
i m sending the detail/snapshort of error.</p>

<p><img src="http://i.stack.imgur.com/ncP0G.jpg" alt="error message"></p>

<p><img src="http://i.stack.imgur.com/o1U14.jpg" alt="enter image description here"></p>

<p><img src="http://i.stack.imgur.com/ncP0G.jpg" alt="error message"></p>
