问题描述
我在 Outlook 中有几个收件箱:my.name@abc.com,以及一些共享收件箱,例如 team.data@abc.com 或 team.ba@abc.com.
I have several inboxes in Outlook: my.name@abc.com, plus a number of shared inboxes like team.data@abc.com for example, or team.ba@abc.com.
按照此方法,我尝试访问自己收件箱中的电子邮件.
By following this method I am trying to access the emails in my own inbox.
问题是,有时收件箱会访问 my.name@abc.com 的邮件,有时它可能是其他任何人!我看过 Omegahat 的解释,但他们的例子主要是针对 excel 的,我没有 VB 经验.
The problem is that sometimes, the inbox accesses mails to my.name@abc.com, sometimes it can be any of the others! I've gone through the Omegahat explanations, but their example is mostly focused on excel, and I have no VB experience.
我想定义从哪个收件箱中检索邮件......到目前为止我的代码(有不同收件箱的问题).干杯.
I would like to define which inbox to retrieve the mails from.. My code so far (with the problem of varying inboxes). Cheers.
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
edit: I am running MSOffice Pro Plus 2016
相关:如何使用 RDCOMClient 从辅助帐户发送 Outlook 电子邮件 - 翻译现有的 VBA 代码?
推荐答案
考虑 Outlook 的 存储 对象:
Consider Outlook's Stores Object:
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()
这篇关于R、RDCOMClient 和 Outlook:使用共享地址访问收件箱邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!