Как разобрать группу контактов / список рассылки и получить электронную почту SMTP? - PullRequest
0 голосов
/ 12 июня 2019

Я работаю над этим некоторое время, и я в замешательстве. Я пробовал несколько разных подходов, чтобы перечислить контактную группу и получить SMTP-письма для ее членов. Другие подходы привели к пустому свойству Address, что приводит к ошибке метода PropertyAccessor.

Sub test()
    Dim oNs As NameSpace
    Dim oFdr As Folder
    Dim oItem As Object, oItems As Items
    Dim strArr(100) As String
    Dim oRec As Recipient, oRecs As Recipients
    Dim oEDL As ExchangeDistributionList
    Dim oAEs As AddressEntries, oAE As AddressEntry
    Dim i As Integer, j As Integer


    Const PR_SMTP_ADDRESS As String = "http://schemas.microsoft.com/mapi/proptag/0x39FE001E"

    'The purpose of this procedure is to write the sender and recipient SMTP emails to string array (strArr).
    'This code is successful unless a recipient is a distribution list.  If a distribution list is encountered,
    'the error below occurs.

    Set oNs = Application.Session
    Set oNs = Application.GetNamespace("MAPI")
    Set oFdr = oNs.GetDefaultFolder(olFolderInbox).Parent
    Set oFdr = oFdr.Folders("!Test Ground")
    Set oItems = oFdr.Items

    For Each oItem In oItems
        If oItem.Class = olMail Then
            strArr(0) = GetSenderSMTP(oItem) 'this sub works fine.
            Debug.Print strArr(0)
            Set oRecs = oItem.Recipients
            Debug.Print oRecs.Count
            i = 0: j = 0
            For Each oRec In oRecs

                i = i + j + 1
                If oRec.AddressEntry.DisplayType <> olUser Then
                    Set oEDL = oRec.AddressEntry.GetExchangeDistributionList
                    'Attempt to parse out each member of a distribution list
                    Set oAEs = oEDL.GetExchangeDistributionListMembers
                    j = 0
                    For Each oAE In oAEs
                        j = j + 1
                        'Err 91 "Object variable or with block not set" occurs on the next line.
                        'I have also tried the .GetPrimarySMTP method
                        strArr(i + j) = oAE.PropertyAccessor.GetProperty(PR_SMTP_ADDRESS)
                        Debug.Print strArr(i + j)
                    Next
                Else
                    strArr(i) = oRec.PropertyAccessor.GetProperty(PR_SMTP_ADDRESS)
                    Debug.Print strArr(i)
                End If
            Next
        End If

    Next
End Sub

Код возвратил объект ошибки 91 или блок не установлен.

...