I am trying to extract the body of a few outlook emails with their email subject containing the keyword "Permission" using RDCOMClient in R.
This is the code that I have written.
OutApp <- COMCreate("Outlook.Application")
OutlookNameSpace <- OutApp$GetNameSpace("MAPI")
folderName <- "Inbox"
search <- OutApp$AdvancedSearch(folderName, "urn:schemas:httpmail:subject like '%Permission%'")
results <- search$Results()
body <- c()
for (i in 1:results$Count()){
body <- c(body, results$Item(i)$Body())
}
When I ran the codes line by line, I am able to obtain the character vector body without error.
However, when I ran the entire chunk together, an error is encountered.
< CheckErrorInfo > 80020009
No support for InterfaceSupportsErrorInfo
CheckErrorInfo -2147352567
Error: Exception occurred.
I had tried adding Sys.sleep(1) as suggested in Running Excel macros from R through RDCOMClient, error -2147418111, both outside and inside the for loop, but I still get the same error.
Ultimately, I would like to run this script automatically using source( ). Could someone please help me understand why this error has occurred, and how do I resolve it?
In addition, if I would like to access a shared inbox instead of my personal inbox, how should I change the folderName so that the search will be done in the correct mailbox?
Thank you!