Extract Outlook Contacts using R

287 Views Asked by At

I am trying to query Outlook Contacts and extract them all in a csv file using R programming language. I have a example piece of code:

#####################################################
library(RDCOMClient)
## init com api
OutApp <- COMCreate("Outlook.Application")
olFolderContacts <- 10

# get the namespace
ns <- OutApp$GetNamespace("MAPI")
# get the contact folder
folderContacts = ns$GetDefaultFolder(olFolderContacts)
# get the contact list
folderItems = folderContacts$Items()
i = 0
# get the first contact
itemObj = folderItems$Item(i+1)
#####################################################
# That's here that it fails
#####################################################
ContactName <- itemObj$GetElement()$Name()
#####################################################

The idea is that the folder contains items which are of different type. How to query the Object COM interface to get the object type or Class and how to invoke the methods related to it?

Thanks,

Maurizio.

1

There are 1 best solutions below

0
On

I have been able to extract the list of my contacts with the following code :

library(RDCOMClient)
Application <- RDCOMClient::COMCreate("Outlook.Application")
ns <- Application$GetNamespace("MAPI") 
foldContact <- ns$GetDefaultFolder(10) 
colItems <- foldContact$Items()$Restrict("[MessageClass]='IPM.Contact'") 
nb_Contact <- colItems$Count()
list_Info_Contact <- list()

for(i in 1 : nb_Contact)
{
  creation_Time <- colItems[[i]]$CreationTime()
  full_Name <- colItems[[i]]$FullName() 
  list_Temp_Info <- list(creation_Time = creation_Time, full_Name = full_Name)
  list_Info_Contact[[i]] <- list_Temp_Info
}