1

I need to retrieve few fields from outlook like Fullname, jobtitle from outlook server using VBscript.

Set oNetwork = CreateObject("WScript.Network")
sDomain = oNetwork.UserDomain
sADSPath= sDomain & "/" & sUser
Set oUser = GetObject("WinNT://" & sADSPath & ",user")
if err.number <> 0 then
objTextFile.WriteLine (sUser)
else
objTextFile.WriteLine (oUser.FullName)
End If

The above script works to get the fullname if id is given in sUser. But the line

objTextFile.WriteLine (oUser.JobTitle)

is not working in the same way to retrieve the title field. Please let me know what property to use to retrieve fields such as Manager Name and Jobtitle and location details from outlook.

Note : I'm using outlook 2010.

Dmitry Streblechenko
  • 62,942
  • 4
  • 53
  • 78
Preeth
  • 11
  • 2

1 Answers1

0

The above code does not use Outlook at all.
Where is your code running? Is it a COM addin or a standalone application?
Take a look at Application.Session.CurrentUser in the Outlook Object Model?
You can either use Recipient.AddressEntry.GetExchangeUser to retrieve the ExchangeUserObject or use AddressEntry.PropertyAccessor to retrieve raw MAPI properties - have a look at the available properties (and their DASL names) in OutlookSpy (I am its author - click IMAPISession button, then QueryIdentity).

Dmitry Streblechenko
  • 62,942
  • 4
  • 53
  • 78
  • It is standalone script. When I execute the enire script I get the user names in a separate text file. (User ids are feeded to the script from a text file) This is the rest of the script on how the data is passed. Set objFSO = CreateObject("Scripting.FileSystemObject") 'Open the text file - strData now contains the whole file strData = objFSO.OpenTextFile(strTextFile,ForReading).ReadAll Set objTextFile = objFSO.OpenTextFile(strWriteFile, ForWriting, True) 'Split the text file into lines arrLines = Split(strData,vbCrLf) 'Step through the lines For Each strLine in arrLines sUser = strLine – Preeth Jan 31 '13 at 04:35
  • You can use the Outlook Object Model to resolve the name and get its details - call Application.Session.CreateRecipient() (returns Recipient object), call Recipient.Resolve, read Recipient.AddressEntry propertty to get the AddressEntry object, use AddressEntry.Fields to read raw MAPI properties or use AddressEntry.GetExchangeUser to get the ExchangeUser object which exposes the JobTitle property. – Dmitry Streblechenko Jan 31 '13 at 16:41