Outlook email .Class = olReport. How do I find emailaddr or date etc, .subject is the only one I can find?

bignose2

Registered User.
Local time
Today, 16:55
Joined
May 2, 2010
Messages
240
Hi,
moved over to 365 as my mail server, for sometime used Outlook to get the email but only ever had olMail object.
this was fine for
.SenderEmailAddress
.ReceivedTime
etc.

However rejected/undelivered/bounced email are under olReport

olReport so far I have only found .Subject
None of the others work.

Anyway to list the all, I would be happy just with the sender email & date/time.

Late binding & would try a references & then remove but prefer not too just in case it adds something that later messes with my distribution copies & also not sure it would auto complete this anyway.

Set oOutlook = CreateObject("Outlook.Application")
Set oNameSpace = oOutlook.GetNamespace("MAPI")
 
Provide rest of code, at least enough to test this.

Don't know if 365 would be any different from 2021 desktop but I can see the following:

.CreationTime
.DeferredDeliveryTime
.ReceivedTime
.Sender
.SenderEmailAddress
.SenderName
.SentOn
 
Thanks for your reply,

Think I have enough now anyway,
From ..

.CreationTime is the only one of the above that works on the olReport.
I can get .body & so can search & get anything else I need, of all the Methods listed cannot see sender email but can select from body.
I must have missed something as surely would have its own .item.

Anyway sorted thanks


I did not post all the code, I figured it was one of those things you either knew or not with the olReport & a lot of code inbetween, I have removed to make clearer.

Code:
  Set oOutlook = GetObject(, "Outlook.Application")        'Bind to existing instance of Outlook
    If Err.Number <> 0 Then        'Could not get instance, so create a new one
        Err.Clear
        Set oOutlook = CreateObject("Outlook.Application")
    End If
 
    Set oNameSpace = oOutlook.GetNamespace("MAPI")
    
    Dim dbs As dao.Database
    Dim r As dao.Recordset
    
    Dim IsSMS As Boolean
    Dim PlainSource As String
    Dim SourceShort As String
    Dim D1, D2, D3
    Dim LoopDates, SplitDates
    Dim i As Integer, iFiltered As Integer
    Dim AttCount As Integer

    Dim myItems As Object   '   Outlook.items
    Dim FilteredItems As Object    '  Outlook.items
    Dim myItem As Object    '    Outlook.MailItem

    Dim FilteredCount As Integer
    Dim EntryIDItem As Variant  ' array here had to be variant
    Dim EntryIDs() As String
    
    Set dbs = CurrentDb
    
    Set r = dbs.OpenRecordset("EmailPasteTable", dbOpenDynaset)
    Set oFolder = oNameSpace.Folders("Bookings@fpkennels.com").Folders("inbox")
    Set oDestFolder = oNameSpace.Folders("Bookings@fpkennels.com").Folders("inbox")   'myInbox.Folders("BookingsRead")

    Set myItems = oFolder.items
    Set FilteredItems = myItems.Restrict("[UnRead] = True")  '("[Categories] = 'Business'")   '("[UnRead] = True")

    FilteredCount = FilteredItems.Count

    ' if no unread, exit
    If FilteredCount = 0 Then GoTo Exit_Outlook_ExtractMessages    ' will run if you remove filter above @@@, for ALL
    
    ReDim EntryIDs(1 To FilteredCount)  ' array same length as filtered count. ODD ,errors later with For Each ..- 1 as atrart from 0

    For iFiltered = 1 To FilteredCount         '  FilteredItems.Count

        Set oItem = FilteredItems(iFiltered)    ' ######## ERROR - took some finding Array Out Of Bounds SEP 24 #############
        
        With oItem
        
            If .Class = olReport Then   'olReport is bounceback etc. with NEW O 365, else crashes
                r.AddNew
                r!Subject = .Subject
                r!Received = now  '.ReceivedTime
                r!tToDo = True
           '     r!Email = .SenderEmailAddress
                EntryIDs(iFiltered) = .EntryID    'save to array to can clear after all loaded & not one at a time, that perhaps cuases issues
                r.Update
            End If
        
            If .Class = olMail Then
                AttCount = .Attachments.Count

                r.AddNew
                r!Subject = .Subject
                    
                r!Source = .HTMLBody
                PlainSource = PlainText(r!Source)
                r!MessageID = .EntryID 

                r!Email = .SenderEmailAddress
                r!Received = .ReceivedTime
                r!Source = .HTMLBody
                    
                r!tToDo = True 
    
                EntryIDs(iFiltered) = .EntryID    'save to array to can clear after all loaded & not one at a time, that perhaps cuases issues

                End If
                    
                r.Update
                    
            End If
        End With

    Next iFiltered
    r.Close

    For Each EntryIDItem In EntryIDs
        Set oOutlookMsg = oNameSpace.GetItemFromID(EntryIDItem)  
        oOutlookMsg.unread = False

    Next EntryIDItem
 
Since you are dealing with O365, I have to ask if you have willingly or inadvertently switched to "New" Outlook. I don't know the details of that beast, but supposedly it is not fully compatible with other Office/Component Object Model operations - which is what you would use to find the things you seek.
 
Hi,

Definitely OLD, originally, way back, had New & actually struggled to revert.

Pretty sure from that learn MS page I have all the Methods, it just does not seem to have email addr. but wonder if just under a name that is not obvious, have tried most now.

Will try some more as a bit of a pain loading the body & searching, easy enough but just unecessary.
 

Users who are viewing this thread

Back
Top Bottom