Click here to Skip to main content
15,896,329 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a page where we can create private areas, I would to send an invite to that area through email, where user click that "activation link" and it open the webpage, where user can login/register and get access to that area.

Its something similar when we receive activation links to activate something.

I just dont understand how can we prepare our webpage to receive a connection from some link (the one was sent to email).

How can I do that ?
Posted
Comments
shakil0304003 31-Oct-10 23:48pm    
Not clear!

1 solution

Example:

string activationCode = System.Guid.NewGuid().ToString();

        string bodyText = "<a href="$href$?ActivationCode=$ActivationCode$">Click Here</a>";

        string url = System.Web.HttpContext.Current.Request.Url.ToString();
        int i = url.LastIndexOf('/');
        url = url.Remove(i + 1);
        url += "Activate.aspx";

        bodyText = bodyText.Replace("$ActivationCode$", activationCode);
        bodyText = bodyText.Replace("$href$", url);
         
       SendEmail("Admin",
                                 "a@a.com",
                                 "hi",
                                 bodyText);

public static void SendEmail(string sender, string receiver, string subject, string body)
        {            
            string fromEmail = ConfigurationManager.AppSettings["ADMIN_EMAIL"].ToString();
            string password = ConfigurationManager.AppSettings["ADMIN_EMAIL_PASSWORD"].ToString();

            System.Net.NetworkCredential cred = new System.Net.NetworkCredential(fromEmail, password);

            string bodyText = Regex.Replace(body, @"<(.|\n)*?>", string.Empty);

            var plainView = AlternateView.CreateAlternateViewFromString(bodyText, null, "text/plain");
            var htmlView = AlternateView.CreateAlternateViewFromString(body, null, "text/html");

            var mail = new MailMessage
            {
                From = new System.Net.Mail.MailAddress(sender, "Farolito's Journey"),
                ReplyTo = new System.Net.Mail.MailAddress(sender, "Farolito's Journey"),
                BodyEncoding = Encoding.GetEncoding("utf-8"),                
                Subject = subject
            };

            mail.To.Add(new MailAddress(receiver));
            mail.AlternateViews.Add(plainView);
            mail.AlternateViews.Add(htmlView);
            mail.Priority = MailPriority.High;            

            var client = new SmtpClient
            {
                Host = ConfigurationManager.AppSettings["ADMIN_EMAIL_HOST"].ToString(),
                UseDefaultCredentials = false,                
                Credentials = cred
            };

            try
            {
                client.Send(mail);
            }
            catch (Exception)
            {
                
            }

            mail = null;
        }
    }


In Activate.aspx

if (Request.QueryString["ActivationCode"] == null)
            Response.Redirect("Default.aspx");

        string activitionCode = Request.QueryString["ActivationCode"];
 
Share this answer
 
v3

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