Guest User

Guest User

  • Tech Writer
  • 2.1k
  • 469.4k

The SMTP server requires a secure connection or the client?

Feb 17 2020 11:38 PM
Hi Mates
 
I have this issue and dont know how to resolve it on my Register ActionResult, kindly please assist me.
  1. [HttpPost]  
  2.         [AllowAnonymous]  
  3.         [ValidateAntiForgeryToken]  
  4.         public async Task<ActionResult> Register(RegisterViewModel model)  
  5.         {  
  6.             if (ModelState.IsValid)  
  7.             {  
  8.                 var user = new ApplicationUser() { UserName = model.UserName };  
  9.                 user.Email = model.Email;  
  10.                 user.ConfirmedEmail = false;  
  11.                 var result = await UserManager.CreateAsync(user, model.Password);  
  12.                 if (result.Succeeded)  
  13.                 {  
  14.                      
  15.   
  16.   
  17.                     MailMessage msg = new MailMessage();  
  18.   
  19.                     msg.From = new MailAddress("[email protected]");  
  20.                     msg.To.Add("[email protected]");  
  21.                     msg.Subject = "test";  
  22.                     msg.Body = "Test Content";  
  23.                     
  24.                     using (SmtpClient client = new SmtpClient())  
  25.                     {  
  26.                         client.EnableSsl = true;  
  27.                         client.UseDefaultCredentials = true;  
  28.                         client.Credentials = new NetworkCredential("[email protected]""Mohali@5050");  
  29.                         client.Host = "smtp.gmail.com";  
  30.                         client.Port = 587;  
  31.                        // client.DeliveryMethod = SmtpDeliveryMethod.Network;  
  32.   
  33.                         client.Send(msg);  // This gets thrown as an error, yes google settings are set all of them.
  34.                     }  
  35.   
  36.                     return RedirectToAction("Confirm""Account"new { Email = user.Email });  
  37.                 }  
  38.                 else  
  39.                 {  
  40.                     AddErrors(result);  
  41.                 }  
  42.             }  
  43.   
  44.             // If we got this far, something failed, redisplay form  478216  
  45.             return View(model);  
  46.         }  
 

Answers (5)