title: How to send email in ASP.NET C#
body: <p>I'm very new to the <a href="http://en.wikipedia.org/wiki/ASP.NET" rel="noreferrer">ASP.NET</a> C# area. I'm planning to send a mail through ASP.NET C# and this is the <a href="http://en.wikipedia.org/wiki/Simple_Mail_Transfer_Protocol" rel="noreferrer">SMTP</a> address from my <a href="http://en.wikipedia.org/wiki/Internet_service_provider" rel="noreferrer">ISP</a>: </p>
  
  <pre><code>smtp-proxy.tm.net.my
  </code></pre>
  
  <p>Below is what I tried to do, but failed.</p>
  
  <pre><code>&lt;%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="SendMail" %&gt;
  &lt;html&gt;
  &lt;head id="Head1" runat="server"&gt;&lt;title&gt;Email Test Page&lt;/title&gt;&lt;/head&gt;
  &lt;body&gt;
      &lt;form id="form1" runat="server"&gt;
          Message to: &lt;asp:TextBox ID="txtTo" runat="server" /&gt;&lt;br&gt;
          Message from: &lt;asp:TextBox ID="txtFrom" runat="server" /&gt;&lt;br&gt;
          Subject: &lt;asp:TextBox ID="txtSubject" runat="server" /&gt;&lt;br&gt;
          Message Body:&lt;br&gt;
          &lt;asp:TextBox ID="txtBody" runat="server" Height="171px" TextMode="MultiLine"  Width="270px" /&gt;&lt;br&gt;
          &lt;asp:Button ID="Btn_SendMail" runat="server" onclick="Btn_SendMail_Click" Text="Send Email" /&gt;&lt;br&gt;
          &lt;asp:Label ID="Label1" runat="server" Text="Label"&gt;&lt;/asp:Label&gt;
      &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>And below is my <a href="http://en.wikipedia.org/wiki/ASP.NET#Code-behind_solutions" rel="noreferrer">code-behind</a>:</p>
  
  <pre><code>using System;
  using System.Web.UI.WebControls;
  using System.Net.Mail;
  public partial class SendMail : System.Web.UI.Page
  {
      protected void Btn_SendMail_Click(object sender, EventArgs e)
      {
          MailMessage mailObj = new MailMessage(
              txtFrom.Text, txtTo.Text, txtSubject.Text, txtBody.Text);
          SmtpClient SMTPServer = new SmtpClient("127.0.0.1");
          try
          {
              SMTPServer.Send(mailObj);
          }
          catch (Exception ex)
          {
              Label1.Text = ex.ToString();
          }
      }
  }
  </code></pre>
  
  <p>PS: I'm sorry that I couldn't understand the receiver/sender SMTP concept, and so I am trying to understand the whole concept from here.</p>