我尝试在网址中对参数email
进行编码,为此我尝试使用HttpUtility.HtmlEncode
,但由于参数不是&#39而无法正常工作; t编码。我怎么能这样做?
尝试
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);
}
}