-2

I am trying to send an email from my project, but I'm having some trouble...

I'm using this code:

private void SendMail()
{
    MailMessage mail = new MailMessage(MailSender, MailReciever, MailSubject, MailContent);
    SmtpClient client = new SmtpClient(SMTPServer);

    client.Send(mail);
}

Then I get an exception :

The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.1 Client was not authenticated

I don't know what to do. Any suggestions ? What am I doing wrong ?

Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
Etrit
  • 865
  • 2
  • 14
  • 25
  • Instead of stating `I don't know what to do` perhaps you could have looked at the `Related` section on this page as well as do a Stackoverflow search for the topic since there are tons of answers as well as working examples.. lack of effort I must say `Etrit` – MethodMan Aug 05 '13 at 12:22

1 Answers1

5

You need to pass the network credential to authenticate the request

client.Credentials = new System.Net.NetworkCredential("yourusername", "yourpassword");
Massimiliano Peluso
  • 26,379
  • 6
  • 61
  • 70