Click here to Skip to main content
15,889,992 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm trying to send users the activation email after they register. Everything's fine except when the user clicks the link it redirects him to the same page from where the email was send. I, however, wants to redirect him to the new page (i.e to Activation.aspx).


This is my web.config code:-

XML
<mailsettings>
  <smtp>
    <network defaultcredentials="false" host="shadi.com" port="21" username="shadi" password="*********" />
  </smtp>
</mailsettings>


What I have tried:

This is my code in C# :-
C#
private void SendActivationEmail(int userid)
   {
       string activationCode = Guid.NewGuid().ToString();
       using (SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["str"]))
       {
           using (SqlCommand cmd = new SqlCommand("INSERT INTO UserActivation VALUES(@UserId, @ActivationCode)"))
           {
               using (SqlDataAdapter sda = new SqlDataAdapter())
               {
                   cmd.CommandType = CommandType.Text;
                   cmd.Parameters.AddWithValue("@UserId", userid);
                   cmd.Parameters.AddWithValue("@ActivationCode", activationCode);
                   cmd.Connection = con;
                   con.Open();
                   cmd.ExecuteNonQuery();
                   con.Close();
               }
           }
       }

       using (MailMessage mm = new MailMessage("shadi@gmail.com", useremail.Text))
       {
           mm.Subject = "Account Activation";
           string body = "Hello " + Convert.ToString(Session["USERNAME"]).Trim() + ",";
           body += "<br /><br />Please click the following link to activate your account";
           body += "<br /><a href="">Click here to activate your account.</a>";
           body += "<br /><br />Thanks and Regards,";
           body += "<br /><br />Shadi Team";
           mm.Body = body;
           mm.IsBodyHtml = true;
           SmtpClient smtp = new SmtpClient();
           smtp.Host = "smtp.gmail.com";
           smtp.EnableSsl = true;
           NetworkCredential NetworkCred = new NetworkCredential("shadi@gmail.com", "********");
           smtp.UseDefaultCredentials = true;
           smtp.Credentials = NetworkCred;
           smtp.Port = 587;
           smtp.Send(mm);
       }

   }


Please Help.
Posted
Updated 20-Aug-16 0:15am
v4

1 solution

provide the activation page url in the href attribute

C#
body += "<br /><a  href='www.xyz.com/Activation.aspx'>Click here to activate your account.</a>";
 
Share this answer
 
v3
Comments
Deepak Kanswal Sharma 20-Aug-16 13:57pm    
Thanks , but I already have this:-

body += "<br />Click here to activate your account."

Don't know why It doesn't appear in the questoin
Karthik_Mahalingam 21-Aug-16 0:12am    
you should give the full url starting from http:www.yourisitename.come/Yourpage.aspx

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