title: Sending a confirmation mail to Email when registering
body: <p>I want to send a confirmation email to a user who has just registered to the website. I googled it several times in order to find a solution but nothing worked so far.. Can you please help me with the code?
  Thanks in advance!</p>
  
  <pre><code>using System.Web;
  using System.Web.UI;
  using System.Web.UI.WebControls;
  using System.Data.SqlClient;
  using System.Configuration;
  using System.Net.Mail;
  using System.Net;
  using System.Text;
  using System.Data;
  
  public partial class Registration : System.Web.UI.Page
  {
  protected void Page_Load(object sender, EventArgs e)
  {
  
      if (IsPostBack)
      {
          SqlConnection con = new     SqlConnection(ConfigurationManager.ConnectionStrings["RegisConnectionString"].ConnectionStr    ing);
          con.Open();
          string cmdStr = "Select count(*) from Table where Username='" +     TextBox1Username.Text + "'";
          SqlCommand userExist = new SqlCommand(cmdStr, con);
      /*  int temp = Convert.ToInt32(userExist.ExecuteScalar().ToString());
          con.Close();
        if (temp == 1)
          {
              Response.Write("username already exists");
          } */
      }
  }
  
  
  
  protected void Submit_Click(object sender, EventArgs e)
  {
  
      SqlConnection con = new     SqlConnection(ConfigurationManager.ConnectionStrings["RegisConnectionString"].ConnectionStr    ing);
      con.Open();
      string insCmd = "Insert into Register (Username, Password, EmailAddress,Fullname,     City) values (@Username, @Password, @EmailAddress, @Fullname, @City)";
      SqlCommand insertUser = new SqlCommand(insCmd, con);
      insertUser.Parameters.AddWithValue("@Username", TextBox1Username.Text);
      insertUser.Parameters.AddWithValue("@Password", TextBox2Password.Text);
      insertUser.Parameters.AddWithValue("@EmailAddress", TextBox4Email.Text);
      insertUser.Parameters.AddWithValue("@Fullname", TextBox5FullName.Text);
      insertUser.Parameters.AddWithValue("@City", TextBox6City.Text);
      {
          try
          {
  
                  insertUser.ExecuteNonQuery();
                  con.Close();
                  Response.Redirect("Login.aspx");
  
          }
          catch (Exception er)
          {
              Response.Write("error: " + er.Message + " ,please try registering again");
          }
  
      }
  }
  </code></pre>