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.
///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 = "[email protected]"
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
The code works but for those coming from an email group ([email protected] for example) or spoofed email addresses.
obj.SenderEmailAddress results in "/O=EXCHANGELABS/OU=EXCHANGE ADMINISTRATIVE GROUP (removedtextforstack)/CN=RECIPIENTS/CN=7E2removedtextforstackF6-USERNAME"
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.