Share via


Here is a sample code to list delegates of the Outlook Mailbox using CDO 1.2.1 via VBScript

This is another simple request that customers do often: 

NOTE: Following programming examples is for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This sample code assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures. This sample code is provided for the purpose of illustration only and is not intended to be used in a production environment.

Dim objSession
Dim strProfileInfo
Dim strServer
Dim strMailbox
Dim objFolder
Dim objMessages
Dim objMessage
Dim oFields
Dim oField1
Dim oField2
Dim oFBFolder

'TODO:Change Server and Mailbox info
strServer="Server"
strMailbox="User"

strProfileInfo = strServer & vbLf & strMailbox

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

writelog( "Mailbox")

writelog( " ==> ")
writelog( objSession.CurrentUser)
writelog( vbCrLf)
Msgbox "Logged On!!!"

' Reference the root folder by passing ID of ""
Set oRoot = objSession.GetFolder("")

'Connect to the Freebusy folder
Set oFBFolder = oRoot.Folders.Item("Freebusy Data")
Set objMessages = oFBFolder.Messages

For Each objMessage In objMessages

If objMessage.subject = "LocalFreebusy" Then
'Get the message fields

Set oFields = objMessage.Fields

On Error Resume Next

For i = 0 to UBound(oFields.Item(&H6844101E).Value(0))

Set oField1 = oFields.Item(&H6844101E) '
PR_SCHDINFO_DELEGATE_NAMES
writelog "DELEGATE NAMES ==> " & oField1.Value(0)(i)
writelog( vbCrLf)

Set oField2 = oFields.Item(&H686B1003) '
PR_DELEGATE_FLAGS
writelog "Delegate can see private ==> " & oField2.Value(0)(i)
writelog( vbCrLf)
Next
End iF
Next

objSession.Logoff

Set objSession =Nothing

Set oField1 = Nothing
Set oField2 = Nothing
Set oFBFolder = Nothing
Set oRoot = Nothing

Msgbox "Done!!!"

Sub WriteLog(ByVal strMessage)
Dim fs
Set fs = CreateObject("Scripting.FileSystemObject")
Dim file
Dim sScriptPath
sScriptPath = Left(WScript.ScriptFullName, InstrRev(WScript.ScriptFullName,
"\"))
Set file = fs.opentextfile(sScriptPath & "DelegateListLog.txt", 8, True)
file.Write strMessage
file.Close
End Sub
.csharpcode, .csharpcode pre { font-size: small; color: black; font-family:
consolas, "Courier New", courier, monospace; background-color: #ffffff;
/*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color:
#008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080;
} .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000;
} .csharpcode .attr { color: #ff0000; } .csharpcode .alt { background-color:
#f4f4f4; width: 100%; margin: 0em; } .csharpcode .lnum { color: #606060; }

Please refer to the following MAPI properties used in the above sample to list delegates of the mailbox:
PidTagScheduleInfoDelegateNames Canonical Property
<https://msdn.microsoft.com/en-us/library/cc839497.aspx>
Contains the names of the delegates.
Associated properties: PR_SCHDINFO_DELEGATE_NAMES, PR_SCHDINFO_DELEGATE_NAMES_A,
PR_SCHDINFO_DELEGATE_NAMES_W
Identifier: 0x6844
PidTagDelegateFlags Canonical Property
<https://msdn.microsoft.com/en-us/library/cc815505.aspx>
Specifies whether a delegate can view the delegator’s private message objects.
Associated properties: PR_DELEGATE_FLAGS
Identifier: 0x686B
If you interested in exploring further details regarding how delegate settings works in Outlook then refer to:
[MS-OXODLGT]: Delegate Access Configuration Protocol Specification
<https://msdn.microsoft.com/en-us/library/cc425488.aspx>
However, if you just targeting Exchange Server 2007, I would highly recommend you to use EWS(Exchange Web Services)