获取连接到邮箱的交换用户列表

时间:2019-01-23 17:47:24

标签: excel vba outlook outlook-vba

我需要让可以访问共享邮箱的Outlook用户。我可以使用excel-vba代码获取用户详细信息,但是此任务超出了我的限制。 有没有办法以编程方式获取此信息? 我通常这样做,但是我使用的对象没有方法返回我需要的值。 任何帮助将不胜感激。

Public Sub listUsers()
    Dim myolApp As Outlook.Application
    Dim myNameSpace As Namespace
    Dim myAddrList As AddressList
    Dim myAddrEntry As AddressEntry
    Dim whoIsThis As String
    Dim exchUser As Outlook.ExchangeUser

    Set myolApp = CreateObject("Outlook.Application")
    Set myNameSpace = myolApp.GetNamespace("MAPI")
    Set myAddrList = myNameSpace.AddressLists("Global Address List")

    Dim FullName As String, LastName As String, FirstName As String
    Dim HomeState As String, PhoneNum As String

    whoIsThis = "Doe, John"

    Set myAddrEntry = myAddrList.AddressEntries(whoIsThis)
    Set exchUser = myAddrEntry.GetExchangeUser

    If Not exchUser Is Nothing Then
        FirstName = exchUser.FirstName
        LastName = exchUser.LastName
        HomeState = exchUser.StateOrProvince
        PhoneNum = exchUser.BusinessTelephoneNumber
        test = exchUser.Alias
        lista2 = exchUser.Alias
        myemail = exchUser.Address
        myemail = exchUser.PrimarySmtpAddress        
        'etc...
    End If
End Sub

1 个答案:

答案 0 :(得分:0)

首先,最好使用Namespace.CreateRecipient / Recipient.Resolve / Recipient.AddressEntry,而不是访问“全局地址列表”列表(名称可以本地化)。

要弄清楚哪个用户有权委派访问特定邮箱,您需要从代表邮箱所有者的PR_EMS_AB_PUBLIC_DELEGATES对象中以IMAPITable的形式打开IMailUser属性。这将需要扩展MAPI(C ++或Delphi),您不能从VBA中做到这一点。如果可以使用Redemption,它将显示RDOAddressEntry。Delegates集合。可以从RDOExchnageMailboxStore。Owner属性中检索RDOAddressEntry对象。您还可以使用RDOExchangeMailboxStore。Delegates集合(它使用EWS)。