I have a number of emails saved outside my Outlook directory, eg. at some file path "C:\\Users\\foo\\bar.msg"
.
I would like to read these emails into R using library(RDCOMClient)
; following this question I have been able to read emails into R from my Outlook folder structure. However given the volume of emails it is not possible to import them into Outlook to read from there.
The answer to this question suggests that within VBA you can use OpenSharedItem to read emails from an external folder, however I haven't been able to translate this into something that works in R. My attempt is:
library(RDCOMClient)
OutApp <- COMCreate("Outlook.Application")
outlookNameSpace <- OutApp$GetNameSpace("MAPI")
message_path <- "C:\\Users\\foo\\bar.msg"
message <- OutApp$OpenSharedItem("message_path")
Turned out there was a wrong object reference in my example above: I reference OutApp
rather than outlookNamespace
, when calling CreateItemFromTemplate
Maintaining the question as this might save somebody else the search and interpolating the VBA solution into R.
Working solution:
library(RDCOMClient)
OutApp <- COMCreate("Outlook.Application")
outlookNameSpace = OutApp$GetNameSpace("MAPI")
message_path <- "C:\\Users\\foo\\bar.msg"
message <- outlookNameSpace$OpenSharedItem(message_path)