routlookrdcomclient

How to retrieve emails by date using RDCOMClient


I am trying to retrieve only emails received "today" from particuarly folder in my outlook inbox. How would I be able to do this? The follow code below allows me to extract emails all from a inbox, but I am only interested in emails that were received today. What would I add to my code?

folderName <-  "Folder2"

## create outlook object
OutApp <- COMCreate("Outlook.Application")
outlookNameSpace <-  OutApp$GetNameSpace("MAPI")

folder <- outlookNameSpace$GetDefaultFolder(6)
fld <-  folder$folders(folderName)
cnt <-  fld$Items()$Count()

emails <- fld$items
resp <-  data.frame(sno = 1:cnt,Text = "",stringsAsFactors=FALSE)

for(i in seq(cnt)){
  d <-  as.data.frame(emails(i)$Body(), stringsAsFactors=FALSE)
  resp$Text[i] = d[1]
  resp$Sender[i] = emails(i)[['SenderName']]
  resp$To[i] = emails(i)[['To']]
  resp$sub[i] = emails(i)[['subject']]
}

Solution

  • Use Items.Find/FindNext or Items.Restrict with a query like [ReceivedTime] >= '02/20/2020 00:00am'