Click here to Skip to main content
15,867,453 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Posted
Comments
Laiju k 5-Nov-14 6:55am    
are you getting any error
Member 10874581 5-Nov-14 6:57am    
yups i am trying since too long but not able to success kindly help me.if u are having auther alternative than kindly send me

1 solution

Um...This may sound really silly, but...did you fill in the right information here:
C#
smtp.Credentials = new NetworkCredential( "yourid@gmail.com", "your passwordd");
Because that looks like you copy'n'pasted it from somewhere without reading the code at all...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900