Search code examples
c#smtpclientnetworkcredentials

SmtpClient is working with wrong credentials


My Smtpclient is working with following setup

SmtpClient client = new SmtpClient();
client.Host = server;
client.UseDefaultCredentials = false;
client.Credentials = new NetworkCredential("username", "totallywrongpassword", "DOMAIN");

try
{
    client.Send(message);
}
 catch
 {
   // no exception is thrown, emails are send
 }

I am providing invalid credentials, yet the emails are being sent.

What am I configuring wrong?

The smtp server and client are on the same local domain.


Solution

  • Most likely is that your SMTP server is set up to allow local networks to send off it without needing credentials. Your code is totally correct and if the server is still letting you send off, I'd contact the administrator first.