title: Extract SMTP address from Exchange User in the FROM field of a message
body: <p>I want to organize messages in folders by domain (and possibly user). I have a script but it can't get the SMTP addresses from exchange users. The below code is an excerpt from the address extractor.</p>
  
  <pre><code>///For each obj in objFolder.Items
      If obj.SenderEmailAddress = "EX" Then
      Set objSender = obj.Sender
          If Not (objSender Is Nothing) Then
              Set objExchUser = Sender.GetExchangeUser()
              If Not (objExchUser Is Nothing) Then
                  strSender = objExchUser.PrimarySmtpAddress
              End If
          End If
      Else
          If obj.SenderEmailAddress = "" Then
          strSender = "ERROR@ERROR.GOV"
          Else
          MsgBox obj.SenderEmailAddress
          'MsgBox obj.PrimarySmtpAddress 'errs out
          'MsgBox Sender.GetExchangeUser() 'errs out
          'MsgBox Obj.Sender.GetExchangeUser() 'errs out
          strSender = obj.PrimarySmtpAddress
          End If
      End If
  ///Next
  </code></pre>
  
  <p>The code works but for those coming from an email group (helpdesk@myexchange.org for example) or spoofed email addresses. </p>
  
  <p>obj.SenderEmailAddress results in "/O=EXCHANGELABS/OU=EXCHANGE ADMINISTRATIVE GROUP (removedtextforstack)/CN=RECIPIENTS/CN=7E2removedtextforstackF6-USERNAME"</p>
  
  <p>I believe this is to be expected, but Sender.GetExchangeUser() gives an Object Required error. I don't particularly want 3000 lines of code to dig through AD to try to look up an AD code/user for every email. We use office 365 and it's managed by many people, so things aren't straitforward with accessing the address lists.</p>