0

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?

Community
  • 1
  • 1
fussmonkey
  • 606
  • 5
  • 19
  • https://support.microsoft.com/en-us/kb/2773786 –  Oct 20 '15 at 19:57
  • @jp2code - right, that's what I'm assuming is the case, that the email group is set up to require authentication. Not having control over the email group administration, I was wondering if I could make sure the SmtpClient *is* authenticated, since this is all internal to our network. – fussmonkey Oct 20 '15 at 20:47
  • I wonder if the issue is that the account this runs with/under is authenticated, but not authorized, and the error message is not accurate? It's something I'd check anyway. To rule that out, I'd make sure I can send to that group, then hard-code my creds into the app to test and see if it goes... – Nikki9696 Oct 20 '15 at 21:36
  • Also, it's been a bit since I've used smtp mail, but don't you have to use a port and SSL to call it with auth? – Nikki9696 Oct 20 '15 at 21:37
  • You could try sending to email recipients one-by-one, and try to find the one it fails on. –  Oct 21 '15 at 00:36
  • I tried using EnableSsl but received an exception "Server does not support secure connections." (I didn't see anything in [this answer](http://stackoverflow.com/a/298379/1389995) indicating that was required to make an Smtp call authenticated, but I tried anyway). I also verified I can email the group through Outlook. I tried hard-coding my credentials into the app as well, and still didn't work. – fussmonkey Oct 21 '15 at 13:31

0 Answers0