我在Outlook中有多个收件箱:my.name@abc.com,以及许多共享收件箱,例如team.data@abc.com或team.ba@abc.com。
在遵循this method之后,我试图访问自己收件箱中的电子邮件。
问题在于,有时收件箱访问邮件到my.name@abc.com,有时可能是其他任何一个!我已经看过Omegahat的解释,但他们的示例主要针对excel,并且我没有VB经验。
我想定义从哪个收件箱中检索邮件。.到目前为止,我的代码(存在收件箱变化的问题)。干杯。
OutApp <- COMCreate("Outlook.Application")
outlookNameSpace = OutApp$GetNameSpace("MAPI")
folder <- outlookNameSpace$Folders(1)$Folders(folderName)
folder$Name(1)
emails <- folder$Items
for (i in 1:10)
{
subject <- emails(i)$Subject(1)
print(emails(i)$Subject())
}
编辑:我正在运行MSOffice Pro Plus 2016
相关:How to use RDCOMClient to send Outlook email from a secondary account - translate existing VBA code?
答案 0 :(得分:1)
考虑Outlook的Stores对象:
OutApp <- COMCreate("Outlook.Application")
OutStores <- OutApp$Session()$Stores()
# 1ST ACCOUNT
myfolder <- OutStores[[1]]$GetRootFolder()$folders(folderName)
# 2ND ACCOUNT
myfolder <- OutStores[[2]]$GetRootFolder()$folders(folderName)
...
甚至遍历所有商店:
OutApp <- COMCreate("Outlook.Application")
OutStores <- OutApp$Session()$Stores()
store_count <- OutStores$Count()
for (i in 1:store_count) {
myfolder <- OutStores[[i]]$GetRootFolder()$folders(folderName)
emails <- myfolder$Items
for (i in 1:10) {
subject <- emails(i)$Subject()
print(subject)
}
}
# QUIT APPLICATION
OutApp$Quit()
# RELEASE COM RESOURCES
subject <- NULL; emails <- NULL; myfolder <- NULL
OutStores <- NULL; OutApp <- NULL
gc()