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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Resolving Email address via Alias

Status
Not open for further replies.

MattSmithProg

Programmer
Sep 9, 2001
76
AU
Hi,

I have a little problem trying to resolve an email address via the alias.

Normally I have this code to resolve an email address and return the display name and office.

Function GetNameAndSiteFromOutlook(sUserId) As Boolean
'sUserId is passed via an input form where the user enters a UserId of a person and then it attempts to return the display name and Office of the person

Dim objSession As MAPI.Session
Dim objMessage As MAPI.Message
Dim objonerecip As MAPI.Recipient
Dim myaddentry As MAPI.AddressEntry
Dim myFields As MAPI.Fields
Dim myoffice As MAPI.Field

'Gets UserId of system machine for logon to Outlook
Call Declaration.GetUserId

Set objSession = CreateObject("MAPI.Session")
objSession.Logon strUserId, , False, False
Set objMessage = objSession.Outbox.Messages.Add
Set objonerecip = objMessage.Recipients.Add (Name:=sUserId, Type:=CdoTo)
objonerecip = sUserId

'Seeing if a user exists.
On Error GoTo X
objonerecip.Resolve (False)
On Error GoTo Proc_Err

'Getting office details
Set myaddentry = objonerecip.AddressEntry
Set myFields = myaddentry.Fields
Set myoffice = myFields.Item(&H3A19001E)
strUserName = myaddentry.Name
strSite = myoffice.Value

Set objSession = Nothing
Set objMessage = Nothing

Exit Function

PROC_ERR:
objSession.Logon , , True, False
Resume Next
X:

GetNameAndSiteFromOutlook = True
Exit Function

End Function

I have now come along a problem where a person's surname is exactly the same as the alias. This is causing the resolve not to work as there are two people that the alias could be.

What I want to do is pass the UserId of the person directly to CDO so it won't look at the display name at all and therefore not have any resolving conflict.

I hope I am making sense. If anyone could help me I would be greatly appreciative.

Thanks

Matt Smith
No two nulls are the same
 
After posting the question I managed to solve it.

Here is what I did.

Function GetNameAndSiteFromOutlook(sUserId) As Boolean

'________________________________________________________________________
'This routine collects a specified users information from the Outlook
'address book. It does this through the use of CDO and MAPI.It places the
'userid in to the address book and since the user id is the alias of the
'email address it is able to determine the site and name of the
'specified user.
'________________________________________________________________________

Dim objSession As MAPI.Session
Dim objAddressList As MAPI.AddressList
Dim objAddressEntries As MAPI.AddressEntries
Dim objAddEntryFilter As MAPI.AddressEntryFilter
Dim objAddressEntry As MAPI.AddressEntry

Dim Counter As Integer

Call Declaration.GetUserId

Set objSession = CreateObject("MAPI.Session")
objSession.Logon strUserId, , False, False

Set objAddressList = objSession.GetAddressList(CdoAddressListGAL)
Set objAddressEntries = objAddressList.AddressEntries
Set objAddEntryFilter = objAddressEntries.Filter
objAddEntryFilter.Name = sUserId

If objAddressEntries.Count < 1 Then GoTo X


Set objAddressEntry = objAddressEntries.GetFirst

For Counter = 1 To objAddressEntries.Count


If UCase(objAddressEntry.Fields.Item(&H3A00001E)) = objAddEntryFilter.Name Then

strUserName = objAddressEntry.Fields.Item(&H3001001E)
strSite = objAddressEntry.Fields.Item(&H3A19001E)

Exit For

End If

Set objAddressEntry = objAddressEntries.GetNext

Next Counter

Set objSession = Nothing

Exit Function

PROC_ERR:
objSession.Logon , , True, False
Resume Next
X:

GetNameAndSiteFromOutlook = True
Exit Function

End Function
No two nulls are the same
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top