Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to search email address in exch 2003

Status
Not open for further replies.

RichardHuang

Technical User
Aug 13, 2003
204
CA
Hello,

I was wondering if there is an efficient way to search who receives the email, for example abc@mydomain.com, when we don't have the user called abc, but we have that email address? Thank you for your help.
 
Does anybody have any idea? Thanks for your help in advance.
 
There is probably a better way, but if you send mail to that address it will show up in the message tracking logs.

Also, in our system if I begin to compose an email using Outlook, after entering an SMTP address I can press "Check Names" and it converts it to the display name.

CCA Citrix 4.0
MCSA: Messaging 2003
293 - passed
 
Thanks for the reply. That's what I did to find out who has that address... I was just thinking if there is a better way :)
 
I would enumerate all of the SMTP addresses to a text file.

Code:
'==========================================================================
'
' NAME: EnumSMTP.vbs
'
' AUTHOR: Mark D. MacLachlan , The Spider's Parlor
' URL: [URL unfurl="true"]http://www.TheSpidersParlor.com[/URL]
' COPYRIGHT (c) 2005 All Rights Reserved
' DATE  : 7/28/2004
'
' COMMENT: Lists SMTP addresses and user names.
'
'    THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
'    ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED To
'    THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
'    PARTICULAR PURPOSE.
'
'    IN NO EVENT SHALL THE SPIDER'S PARLOR AND/OR ITS RESPECTIVE SUPPLIERS 
'    BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
'    DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
'    WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
'    ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
'    OF THIS CODE OR INFORMATION.
'==========================================================================

vbComma = chr(44)
Set Root = GetObject("LDAP://RootDSE")
DNC = "LDAP://" & Root.Get("DefaultNamingContext")

Const ADS_SCOPE_SUBTREE = 2
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCOmmand.ActiveConnection = objConnection
objCommand.CommandText = _
"Select mail, cn, ProxyAddresses from '" & DNC & "' " _
& "where mail='*@*' ORDER BY cn"
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Timeout") = 30 
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE 
objCommand.Properties("Cache Results") = False
report = report & "Name" & vbcomma & "SMTP" & vbCrLf
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst
i = 0
Do Until objRecordSet.EOF
strName = objRecordSet.Fields("cn")
Set regEx = New RegExp ' Create regular expression.
Set regEx1 = New RegExp ' Create regular expression.
regEx.Pattern = "^smtp:" ' Set pattern.
regEx1.Pattern = "^SMTP:SystemMailbox{" ' Set pattern.
regEx.IgnoreCase = True ' Set case sensitivity.
regEx1.IgnoreCase = True ' Set case sensitivity.
'go through each of the elements in ProxyAddresses only keep those that start with smpt:
arrProxylist = objRecordSet.Fields("ProxyAddresses").Value
For each Addy in arrProxylist
	retVal = regEx.Test(Addy) ' Execute the search for smtp:.
	If retVal Then
		retVal1 = regEx1.Test(Addy) ' Execute the search for SystemMailbox.
		If NOT retVal1 Then
			i = i + 1 
			report = report & strName & vbComma & "     " & Addy & vbCrLf
		End IF
	End If
Next
objRecordSet.MoveNext
Loop

Set fso = CreateObject("Scripting.FileSystemObject")
Set ts = fso.CreateTextFile ("EnumeratedSMTPAddresses.txt", ForWriting)
ts.write report
wscript.echo "Report Created"
set ts = nothing

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top