Guest User

Guest User

  • Tech Writer
  • 2.1k
  • 469.6k

Failed to connect to third party, using smtp client?

Feb 5 2020 7:12 AM
Hi Team
 
I have this issue, each time i am registering the new user, its connection failure to third party. I am using smtp client mail and this domain is gmail. The question why am i getting this often and its not even send a confirming email to the user. It does writes this query to the database colum. What could an issue?
  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.               System.Net.Mail.MailMessage m = new System.Net.Mail.MailMessage(  
  15.                   new System.Net.Mail.MailAddress("[email protected]""Web Registration"),  
  16.                   new System.Net.Mail.MailAddress(user.Email));  
  17.               m.Subject = "Email confirmation";  
  18.               m.Body = string.Format("Dear {0}<BR/>Thank you for your registration, please click on the below link to complete your registration: <a href=\"{1}\" title=\"User Email Confirm\">{1}</a>", user.UserName, Url.Action("ConfirmEmail""Account"new { Token = user.Id, Email = user.Email }, Request.Url.Scheme));  
  19.               m.IsBodyHtml = true;  
  20.               System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient("smtp.gmail.com");  
  21.               smtp.Credentials = new System.Net.NetworkCredential("[email protected]""password");  
  22.               smtp.EnableSsl = true;  
  23.               smtp.Send(m);  
  24.               return RedirectToAction("Confirm""Account"new { Email = user.Email });  
  25.           }  
  26.           else  
  27.           {  
  28.               AddErrors(result);  
  29.           }  
  30.       }  
  31.   
  32.       // If we got this far, something failed, redisplay form  
  33.       return View(model);  
  34.   }  
 

Answers (5)