0

I am trying to send an email with security code with ASP.NET

        int code = random.Next(1000, 9999);
        string text = "Your security code is "+ code +" ";
        MailMessage message = new MailMessage("//myemail//", Email.Text.Trim(),"Changing Password", text);
        message.IsBodyHtml = true;

        SmtpClient client = new SmtpClient("//smtp host//",//smtp port// );
        client.EnableSsl = true;
        client.Credentials = new NetworkCredential("//myemail//","//mypassword//");
        client.Send(message);

If I use gmail it throws Authentication Error:

System.Net.Mail.SmtpException: 'The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.0 Authentication Required. Learn more at'

And if I use my other email it throws this after 2-3 minutes:

System.Net.Mail.SmtpException: 'The operation has timed out.'
DimityrU
  • 11
  • 5
  • 1
    Have you allowed less-secure apps to send email in gmail? [Sending email through Gmail SMTP server with C#](https://stackoverflow.com/a/707892/1115360). – Andrew Morton Dec 02 '21 at 19:50
  • Just Enable it and now work fine, but why doesn't work with my other email? – DimityrU Dec 02 '21 at 20:04

0 Answers0