title: How to send mails using SmtpClient and DefaultNetworkCredentials to a distribution list that only allows authenticated senders?
body: <p>I'm trying to send automated emails from a C# console application from machines to clients all on the same domain via our internal Exchange 2007 server (using SMTP), but I'm hitting a snag with distribution lists that only allow authenticated senders. Basically the mails I'm sending are getting rejected by Exchange with:</p>
  
  <p><code>#550 5.7.1 RESOLVER.RST.AuthRequired; authentication required ##rfc822;AuthTESTGroup@example.com</code></p>
  
  <p>I'm using <code>System.Net.Mail.SmtpClient</code> and setting the Credentials property to <code>System.Net.CredentialCache.DefaultNetworkCredentials</code>, but somewhere along the line, the credentials of the account running this program (me, a valid domain user with a valid mailbox) are not getting passed down to Exchange correctly.</p>
  
  <p>I'm using <code>System.Net.CredentialCache.DefaultNetworkCredentials</code> because I do not want to hard code a username or password (either in the code itself or in any sort of configuration file); I want the process to authenticate with our SMTP server using Windows authentication.</p>
  
  <p>Here is a test program I've been using to reproduce the problem (domain names have been anonomized):</p>
  
  <pre><code>using System;
  using System.Net.Mail;
  
  namespace ConsoleApplication1
  {
      class Program
      {
          static void Main()
          {
              var smtpClient = new SmtpClient
                                   {
                                       Host = "MAIL",
                                       Port = 25,
                                       DeliveryMethod = SmtpDeliveryMethod.Network,
                                       Credentials = System.Net.CredentialCache.DefaultNetworkCredentials
                                   };
  
              var mailMessage = new MailMessage
                                    {
                                        Body = "Testing",
                                        From = new MailAddress(Environment.UserName + "@example.com"),
                                        Subject = "Testing",
                                        Priority = MailPriority.Normal
                                    };
  
              mailMessage.To.Add("AuthTESTGroup@example.com");
  
              smtpClient.Send(mailMessage);
          }
      }
  }
  </code></pre>
  
  <p>Whenever I run this as myself (again, I'm a valid user on the domain, with an existing mailbox on the Exchange server) I get an undeliverable bounce message from Exchange with the response:</p>
  
  <p><code>#550 5.7.1 RESOLVER.RST.AuthRequired; authentication required ##rfc822;AuthTESTGroup@example.com</code></p>
  
  <p>I talked to our Exchange server admin and he saw the following error from the Exchange server's event log:</p>
  
  <pre><code>Account For Which Logon Failed:
    Security ID: NULL SID
    Account Name: 
    Account Domain: 
  
  Failure Information:
    Failure Reason: Unknown user name or bad password.
    Status:         0xc000006d
    Sub Status:     0xC0000064
  </code></pre>
  
  <p>Apparently that status code and sub status code translate to:</p>
  
  <p><code>0xc000006d This is either due to a bad username or authentication information.  Usually logged as status code with 0xc0000064 as substatus</code></p>
  
  <p><code>0xC0000064 user name does not exist</code></p>
  
  <p>So again, it's as if somewhere along the line, my Windows credentials are not getting passed down to the Exchange server even though I'm setting the <code>SmtpClient.Credentials</code> to <code>System.Net.CredentialCache.DefaultNetworkCredentials</code></p>
  
  <p>Any ideas?</p>
  
  <p>Thanks in advance!</p>