I've got a C# WPF application that is supposed to send email to an internal email group in certain situations. It works in some cases, but some of the distribution groups seem to be set up in a way that requires authentication, and the Exchange server is providing this message:
550 5.7.1 RESOLVER.RST.AuthRequired; authentication required ##rfc822
This is an internal SMTP server, sending to an internal email address.
I looked into authentication for an SmtpClient object, and it seemed to revolve around setting the .Credentials
property on the SmtpClient. However it doesn't seem to work for me, whether I'm using .UseDefaultCredientials
or if I'm setting a NetworkCredential
object.
Here's some sample code I put together - I'm able to replicate the error my application is experiencing when I try to email the same group the error occurred for.
SmtpClient smtpClient = new SmtpClient();
MailMessage message = new MailMessage();
smtpClient.Host = "smtpserver.domain.com";
smtpClient.UseDefaultCredentials = true;
/* These are other combinations I tried, all to no avail */
//smtpClient.UseDefaultCredentials = false;
//smtpClient.Credentials = CredentialCache.DefaultNetworkCredentials;
//smtpClient.Credentials = new NetworkCredential("username", "password");
message.From = new MailAddress("from@domain.com");
message.Sender = message.From;
message.To.Add("groupname@domain.com");
message.CC.Add("from@domain.com");
message.Body = "Testing email group delivery";
message.Subject = "Testing";
smtpClient.Send(message);
Since this is running as a client application, I would've actually expected .UseDefaultCredentials = true
to work. What am I missing?