问题
Following Greg Thatcher's answer (accepted answer) to How to retrieve Outlook inbox emails using R RDCOMClient?, I wrote some code to search through my inbox and find an email report I receive everyday. The code begins with -
library(RDCOMClient)
folderName = "Inbox"
OutApp = COMCreate("Outlook.Application")
outlookNameSpace = OutApp$GetNameSpace("MAPI")
folder = outlookNameSpace$Folders(1)$Folders(folderName)
emails = folder$Items
This was working last week but systems typically restart over the weekend, and now this is not working, and I have no idea why. I get an error on the second to last line in the code snippet outlookNameSpace$Folders(1)$Folders(folderName)
-
<checkErrorInfo> 80020009
No support for InterfaceSupportsErrorInfo
checkErrorInfo -2147352567
Error: Exception occurred.
However, in trying to troubleshoot, I came across Download attachment from an outlook email using R using which I wrote out -
library(RDCOMClient)
OutApp = COMCreate("Outlook.Application")
search = OutApp$AdvancedSearch("Inbox", "urn:schemas:httpmail:subject = 'Finding Memo - Specific Theme'")
This seems to work because I get the right number when I do search$Results()$Count()
.
Problem is I cannot (or do not know how to) use this second method for my process because the while the beginning part of the subject of the email report stays the same, the end keeps changing. The first method allows me to use grepl()
on the subject of the emails.
If someone could help me understand what is causing first method to break or guide me on modifying the second method to work with grepl()
?
回答1:
while the beginning part of the subject of the email report stays the same, the end keeps changing.
You could use like in combination with %
then:
library(RDCOMClient)
OutApp <- COMCreate("Outlook.Application")
search <- OutApp$AdvancedSearch("Inbox", "urn:schemas:httpmail:subject like 'Finding Memo%'")
while (search$Results()$Count() == 0) TRUE
for (x in seq_len(search$Results()$Count())) {
print(search$Results()$Item(x)$Subject())
}
This was working last week (...), and now this is not working. (...) If someone could help me understand what is causing first method to break
Since it's not reproducible and you gave no info on what changed, this will be difficult.
来源:https://stackoverflow.com/questions/53157959/downloading-attachment-from-outlook-into-r