4
Answers

sending mail in mvc

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("khushboosahu10@gmail.com""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)

1
Photo of Amit Gupta
NA 16.5k 25.7k 7y
You need to alow lessSecureApp to true in the below link and then try https://myaccount.google.com/security
Accepted
0
Photo of Khushboo Kumari
NA 89 1.9k 7y
thanks to all
0
Photo of Rajeesh Menoth
NA 24.7k 629.6k 7y
Hi,
 
5.5.1 Error is related to "SMTP Server Requires a Secure Connection" . So please check the following steps.
  • Enter the correct login password.
  • To remove 2-Step Verification.
  • You have to enable login from other timezone / ip for your google account.To do this follow the link and allow access by clicking the continue button.
  • Go to security settings at the following link and enable less secure apps . So that you will be able to login from all apps.
Reference :
 
http://www.c-sharpcorner.com/blogs/smtp-server-requires-a-secure-connection1
 
http://www.c-sharpcorner.com/UploadFile/2a6dc5/how-to-send-a-email-using-Asp-Net-C-Sharp/
0
Photo of Srikant Maruwada
NA 501 4.4k 7y
Please refer the below article.
 
https://www.emailarchitect.net/easendmail/kb/csharp.aspx?cat=2