Im working on an web application i got stuck between this email sending code.I am working on contact page where anyone can send you email as you guys know that.This code in working fine but i can't pass through this error
as i said im working with Asp.Net Mvc so here is my POST controller im using gmail account so that it won't conflict between any mail services.
public ActionResult sendemail()
{
return View();
}
[HttpPost]
public ActionResult sendemail(string to, string from, string subject, string body, string pwd)
{
SmtpClient client = new SmtpClient();
client.Host = "smtp.gmail.com";
client.Port = 587;
client.EnableSsl = true;
client.UseDefaultCredentials = true;
client.Credentials = new NetworkCredential("faseehyasin12@gmail.com", pwd);
client.DeliveryMethod = SmtpDeliveryMethod.Network;
MailMessage mail = new MailMessage();
mail.To.Add(to);
mail.From = new MailAddress(from);
mail.Subject = subject;
mail.Body = body;
try
{
client.Send(mail);
Response.Write("ok");
return View();
}
catch(Exception e)
{
throw e;
}
}
and here is my view and i want to ask do i really need a password to send email to someone in this code ?
and my GET controller is empty with only written code is return view() so i won't bother to take ss for that. i have also allowed "less secure app" but it still gives me this error. Need Help