Guest User

Guest User

  • Tech Writer
  • 2.1k
  • 474.4k

SMTP Server requires a secure connection or client

Apr 27 2020 12:44 PM
I am having this issue each time when i try to register new users to my web application. Here is the logic.
  1. <connectionStrings>  
  2.     <add name="DefaultConnection" connectionString="Data Source=GcobaniM-L\SQLEXPRESS;Initial Catalog=eNtsaRegistration;Integrated Security=True" providerName="System.Data.SqlClient" />  
  3.   </connectionStrings>  
  4.   
  5.        public Task SendAsync(IdentityMessage message)  
  6.         {  
  7.             // Plug in your email service here to send an email.  
  8.             var mailMessage = new MailMessage();  
  9.             mailMessage.To.Add(new MailAddress(message.Destination));  
  10.             mailMessage.From = new MailAddress("[email protected]");  
  11.             mailMessage.Subject = message.Subject;  
  12.             mailMessage.IsBodyHtml = true;  
  13.             mailMessage.Body = message.Body;  
  14.             using (var smtp = new SmtpClient())  
  15.             {  
  16.                 var credential = new NetworkCredential  
  17.                 {  
  18.                     UserName = "[email protected]",  
  19.                     Password = "***"  
  20.                 };  
  21.                 smtp.Host = "smtp.gmail.com";  
  22.                 smtp.Port = 587;  
  23.                 smtp.EnableSsl = true;  
  24.                 smtp.UseDefaultCredentials = false;  
  25.                 smtp.Credentials = credential;  
  26.                 smtp.Send(mailMessage);  
  27.             }  
  28.             return Task.FromResult(0);  
  29.         }  
  30.     }  

Answers (2)