提取Exchange用户的AddressEntry对象详细信息

时间:2013-10-06 15:10:24

标签: outlook-vba

有没有办法通过VBA提取此对话框中的详细信息?

Details Dialog Box http://i.msdn.microsoft.com/dynimg/IC84336.gif

我需要,尤其是电子邮件地址标签中的内容。

3 个答案:

答案 0 :(得分:1)

我的功能是阅读地址簿:

Function Get_mail(Absender As String)
Dim OutApp As Outlook.Application
Dim OutTI As Outlook.TaskItem
Dim OutRec As Outlook.Recipient

  Set OutApp = New Outlook.Application
  Set OutTI = OutApp.CreateItem(3)
  OutTI.Assign

  Set OutRec = OutTI.Recipients.Add(Absender)
  OutRec.Resolve

   If OutRec.Resolved Then
    On Error GoTo exit_function
        Get_mail = OutRec.AddressEntry.GetExchangeUser.PrimarySmtpAddress
   End If
exit_function: Exit Function
  Set OutApp = Nothing
  Set OutTI = Nothing
End Function

据我所知,你只能从mail-addresses-tab中读出主邮件地址;看看还有什么东西会删除“.PrimarySmtpAddress”这个部分,你应该得到其他属性列表。

我很确定您需要Microsoft Outlook 14.0对象库上的引用。

输入“Absender”可以是任何字符串。如果此字符串可以解析为outlook-mail中的地址簿条目,那么上面的代码也会得到肯定的结果。 要调用该函数,例如,如果你有一个字符串“mail_adress_from_adressbook”,你会把:

mail_adress_from_adressbook = get_mail("Joe Smith")

我希望这有帮助, 最大

答案 1 :(得分:1)

你可以轻松获得这些字段,电子邮件地址是更难的部分。参考文献:Microsoft Exchange Property Tags

此代码导出一些细节,但最重要的是将电子邮件地址导出到文本文件。

Sub ListGAL()
    On Error Resume Next
    Const LogFile = "C:\Test\OLK_GAL.log"
    Const sSCHEMA = "http://schemas.microsoft.com/mapi/proptag/0x"
    Const PR_EMS_AB_PROXY_ADDRESSES = &H800F101E

    Dim oNameSpace As NameSpace, oGAL As AddressList, oEntry As AddressEntry
    Dim oFSO As Variant, oLF As Variant, oExUser As ExchangeUser, i As Long

    ' Oulook objects
    Set oNameSpace = Outlook.Application.GetNamespace("MAPI")
    ' Global Address List object
    Set oGAL = oNameSpace.AddressLists("Global Address List")
    '----------
    ' Log file objects
    Set oFSO = CreateObject("Scripting.FileSystemObject")
    Set oLF = oFSO.CreateTextFile(LogFile)
    '----------
    For Each oEntry In oGAL.AddressEntries
        i = i + 1
        Debug.Print i & vbTab & oEntry.Name
        If oEntry.AddressEntryUserType = olExchangeUserAddressEntry Then
            oLF.WriteLine "Entry " & i & " (olExchangeUserAddressEntry)"
            oLF.WriteLine "Name: " & oEntry.Name
            oLF.WriteLine "Address: " & oEntry.Address
            Set oExUser = oEntry.GetExchangeUser
            ' SMTP ADDRESSES
            oLF.WriteLine "SMTP Addresses:"
            oLF.WriteLine vbTab & Join(oExUser.PropertyAccessor.GetProperty(sSCHEMA & Hex(PR_EMS_AB_PROXY_ADDRESSES)), vbCrLf & vbTab)
            Set oExUser = Nothing
            oLF.WriteLine String(50, Chr(151)) ' Separator
        End If
    Next
    '----------
    ' Close Log File, clean up
    oLF.Close
    Set oGAL = Nothing
    Set oNameSpace = Nothing
    Set oLF = Nothing
    Set oFSO = Nothing
End Sub

答案 2 :(得分:0)

当然,请使用AddressEntry.PropertyAccessor.GetProperty

可以使用OutlookSpy检索DASL属性名称:或者单击“IAddrBook”按钮以深入查看特定地址条目,或者如果您有一条发送给其中一个GAL收件人的邮件,请单击“IMessage”按钮,转到在GetRecipientTable选项卡上,双击收件人将其作为IMailUser打开。