-2

I am trying to send an e-mail from my C# code.Here is an example

MailMessage message = new MailMessage();
            message.To.Add("milos90zr@gmail.com");
            message.Subject = "Registration";
            message.From = new System.Net.Mail.MailAddress("milos90zr@hotmail.com");
            message.Body = "OK";
            SmtpClient smtp = new SmtpClient();
            smtp.Host = "smtp.gmail.com";
            smtp.Send(message);

But my code breaks and here is the error:

The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.0 Must issue a STARTTLS command first. hn4sm3874638bkc.2 - gsmtp
It'sNotALie.
  • 22,289
  • 12
  • 68
  • 103
daidai
  • 531
  • 5
  • 10
  • 22

1 Answers1

2

You have to turn on encryption.

Put this line somewhere before smtp.Send()

smtpClient.EnableSsl = true;
Kamil
  • 13,363
  • 24
  • 88
  • 183