0

I'm trying encode a param email in an url, to do this I'm trying use HttpUtility.HtmlEncode but it doesn't work because the parameter isn't encoded. How could I do this ?

Trying

private void sendMailToValidation(String email){ 
            //String server = HttpContext.Current.Request.Url.Host;
            //encripta a url HttpUtility.HtmlEncode
            string absoluteURL = "http://" + HttpContext.Request.Url.Authority + "/Usuario/validaEmail?email=";
            try{
                MailMessage mail = new MailMessage();
                mail.To.Add(email);
                mail.From = new MailAddress("myemail@gmail.com");
                mail.Subject = "MeuPedido validação de email";
                string url = absoluteURL + HttpUtility.HtmlEncode(email);
                mail.Body = "<html><body><a href=\"" + url + "\">Test</a></body></html>"; 
                mail.IsBodyHtml = true;
                SmtpClient smtp = new SmtpClient();
                smtp.Host = "smtp.gmail.com";
                smtp.Port = 587;
                smtp.UseDefaultCredentials = false;                
                smtp.Credentials = new System.Net.NetworkCredential("myemail@gmail.com", "xxxx");// Enter seders User name and password
                smtp.EnableSsl = true;
                smtp.Timeout = 20000;
                smtp.Send(mail);
            }catch (SmtpException e){
                Console.WriteLine(e.StackTrace);
            }
        }
FernandoPaiva
  • 4,410
  • 13
  • 59
  • 118

0 Answers0