-2

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

MailMessage message = new MailMessage();
            message.To.Add("[email protected]");
            message.Subject = "Registration";
            message.From = new System.Net.Mail.MailAddress("[email protected]");
            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
1
  • You need authentication using the NetworkCredential object. Commented Jun 25, 2013 at 20:04

1 Answer 1

2

You have to turn on encryption.

Put this line somewhere before smtp.Send()

smtpClient.EnableSsl = true;
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.