I have a nice long html web design. My goal is to send an e-mail by clicking the button at the bottom of this page.
First of all, I assign all the html code of the web page open on the javascript side to a variable.
var pageContent = $("body").html();
I'm sending this variable to the web service running in my local
$.getJSON("MailSend?mail_adres=example@gmail.com&content=" + pageContent + "", function (datas)
{
console.log(datas);
});
On the asp.net mvc side, the back-end code of this json web service is as follows;
public JsonResult MailSend(string mail_adres,string content)
{
if (ModelState.IsValid)
{
MailMessage mail = new MailMessage();
mail.To.Add(mail_adres);
mail.From = new MailAddress("example@mydomain.com");
mail.Subject = "Try mail";
string Body = content.ToString();
mail.Body = Body;
mail.IsBodyHtml = true;
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.mydomain.com";
smtp.Port = 587;
smtp.UseDefaultCredentials = false;
smtp.Credentials = new System.Net.NetworkCredential("example@mydomain.com", "mypassword");
smtp.EnableSsl = false;
smtp.Send(mail);
return Json("ok",JsonRequestBehavior.AllowGet);
}
else
{
return Json("no", JsonRequestBehavior.AllowGet);
}
}
Potentially malicious code has been detected on the client, but this is normal. There are special and different characters such as < > in html codes
Full error text: System.Web.HttpRequestValidationException: A potentially harmful value Request.QueryString was detected on the client.
Screenshot of trying to send html code directly without the selected e-mail address;
What should I do for this?