-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 ?

1
  • 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 Commented Aug 5, 2013 at 12:22

1 Answer 1

5

You need to pass the network credential to authenticate the request

client.Credentials = new System.Net.NetworkCredential("yourusername", "yourpassword");
Sign up to request clarification or add additional context in comments.

5 Comments

Extremely over answered topic...
May also need to EnableSsl (depending on the smtp server).
That does not make it available for Downvote ...
@Etrit:- Please accept this as an answer then ...
Done. Just needed to wait the countdown to accept an answer :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.