Khushboo Kumari

Khushboo Kumari

  • NA
  • 112
  • 14.5k

sending mail in mvc

Jan 24 2018 4:59 AM
please help me to solve
 
error->Additional information: The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required. 
 
my code is like below 
  1. [HttpPost]  
  2. public ViewResult Index(mail_sending.Models.MailModel _objModelMail)  
  3. {  
  4. if (ModelState.IsValid)  
  5. {  
  6. MailMessage mail = new MailMessage();  
  7. mail.To.Add(_objModelMail.To);  
  8. mail.From = new MailAddress(_objModelMail.From);  
  9. mail.Subject = _objModelMail.Subject;  
  10. string Body = _objModelMail.Body;  
  11. mail.Body = Body;  
  12. mail.IsBodyHtml = true;  
  13. SmtpClient smtp = new SmtpClient();  
  14. smtp.Host = "smtp.gmail.com";  
  15. smtp.Port = 587;  
  16. smtp.UseDefaultCredentials = false;  
  17. smtp.Credentials = new System.Net.NetworkCredential("[email protected]""shushiladevi"); // Enter seders User name and password  
  18. smtp.EnableSsl = true;  
  19. smtp.Send(mail);  
  20. return View("Index", _objModelMail);  
  21. }  
  22. else  
  23. {  
  24. return View();  
  25. }  
  26. } 

Answers (4)