0

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!

Community
  • 1
  • 1
Wyn Z.
  • 35
  • 4
  • The search function takes a little while to complete. Try putting a `Sys.sleep(10)` in between your `search <- ` and `result <- ` lines. – Matt Jewett Jan 30 '19 at 19:43
  • @MattJewett Thank you, It worked perfectly! May I know if you have any idea how should I change my code so that the search could be done in a shared inbox rather than my own outlook inbox? – Wyn Z. Feb 11 '19 at 03:51

0 Answers0