i am using this code for registration..
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ttConnectionString"].ConnectionString);
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
MailMessage msg;
SqlCommand cmd = new SqlCommand();
string activationurl = string.Empty;
string emailid = string.Empty;
try
{
cmd = new SqlCommand("insert into touch ( firstname, secondname, emailid ,password) values ( @firstname, @secondname, @emailid, @password)", con);
cmd.Parameters.AddWithValue("@firstname", TextBox1.Text.Trim());
cmd.Parameters.AddWithValue("@secondname", TextBox2.Text.Trim());
cmd.Parameters.AddWithValue("@emailid", TextBox3.Text.Trim());
cmd.Parameters.AddWithValue("@password", TextBox4.Text.Trim());
con.Open();
cmd.ExecuteNonQuery();
con.Close();
msg = new MailMessage();
SmtpClient smtp = new SmtpClient();
emailid = TextBox3.Text;
msg.From = new MailAddress(" touchsoft@gmail.com");
msg.To.Add(emailid);
msg.Subject = " account activation";
activationurl = Server.HtmlEncode( http://localhost:36038/TOUCHSOFT11/activation.aspx? userid = "+ fetchuserid( email) + "&emailid" = " + emailid);
msg.Body = "hi" + TextBox1.Text + "!\n"+ "Thanks for showing interest and registring in
webcodeexpert.com " +
" Please click here to activate your account and enjoy our services");
msg.IsBodyHtml = true;
smtp.Credentials = new NetworkCredential( "yourid@gmail.com", "your passwordd");
smtp.Port = 587;
smtp.Host = " smtp.gmail.com";
smtp.EnableSsl = true;
smtp.Send( msg);
clearcontrol();
ScriptManager.RegisterStartupScript(this, this.GetType(), "Message", "alert('Confirmation Link to activate your account has been sent to your email address')", true);
}
catch (Exception ex)
{
ScriptManager.RegisterStartupScript(this, this.GetType(), "Message", "alert('Error occured : " + ex.Message.ToString() + "');", true);
return;
}
}
public void clearcontrol()
{
TextBox1.Text = string.Empty;
TextBox2.Text = string.Empty;
TextBox3.Text = string.Empty;
TextBox4.Text = string.Empty;
TextBox1.Focus();
}
private string fetchuserid(string email)
{
SqlCommand cmd1 = new SqlCommand();
cmd1 = new SqlCommand(" select userid from touch where email = @email", con);
cmd1.Parameters.AddWithValue("@email", email);
con.Open();
string userid = Convert.ToString(cmd1.ExecuteScalar());
con.Close();
cmd1.Dispose();
return userid;
}
}
and code for when user click on activation link..
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
ActivateMyAccount();
}
}
private void ActivateMyAccount()
{
SqlConnection con = new SqlConnection();
SqlCommand cmd = new SqlCommand();
try
{
con = new SqlConnection(ConfigurationManager.ConnectionStrings["conStr"].ConnectionString);
if ((!string.IsNullOrEmpty(Request.QueryString["UserID"])) & (!string.IsNullOrEmpty(Request.QueryString["EmailId"])))
{ //approve account by setting Is_Approved to 1 i.e. True in the sql server table
cmd = new SqlCommand("UPDATE Tb_Registration SET Is_Approved=1 WHERE UserID=@UserID AND EmailId=@EmailId", con);
cmd.Parameters.AddWithValue("@UserID", Request.QueryString["UserID"]);
cmd.Parameters.AddWithValue("@EmailId", Request.QueryString["EmailId"]);
if (con.State == ConnectionState.Closed)
{
con.Open();
}
cmd.ExecuteNonQuery();
Response.Write("You account has been activated. You can
Login now! ");
}
}
catch (Exception ex)
{
ScriptManager.RegisterStartupScript(this, this.GetType(), "Message", "alert('Error occured : " + ex.Message.ToString() + "');", true);
return;
}
finally
{
con.Close();
cmd.Dispose();
}
}
and mine database having 5 fields
userid, firstname, secondname, email, password, and is_app fields kindly help me i am not able to sending confirmation mail kindly help me guys