5

The outlook account that I am using has multiple mailboxes set up and although the following answer seems to show how to use the function, I am unable to get this to work as I have multiple mailboxes with the "Inbox" folder. Download attachment from an outlook email using R

To access the relevant folder normally, I would use the below code:

OutApp = COMCreate("Outlook.Application")
outlookNameSpace = OutApp$GetNameSpace("MAPI")
folder = outlookNameSpace$Folders(14)$Folders("Inbox")

It appears I need another line or so, prior to calling the inbox in the below:

search = OutApp$AdvancedSearch("Inbox", "urn:schemas:httpmail:subject = 'test subject'")
JHardy16
  • 51
  • 2
  • It would be intuitive if you could replace`"inbox"` with `folder`, but that doesn't work. I have not found any documentation for AdvancedSearch that helps describe what form the argument could take. – Mark Neal Jan 07 '20 at 00:57
  • Hello, any update with this? I am into same issue where I need have two mail accounts linked to my Outlook and I need to take attachments from specific account and folder. Thank you in advance. – Bury Jun 15 '20 at 12:50

1 Answers1

0

This worked for me. Make sure to enclose the path in single quotes as part of the path string.

outlookNameSpace = outlook_app$GetNameSpace("MAPI")
mailbox <- outlookNameSpace$Folders(2)
path <- mailbox$Folders("Inbox")$FolderPath()

search <- outlook_app$AdvancedSearch(
  paste0("'", path, "'"), "urn:schemas:httpmail:subject = 'test'"
)