我一直在使用RDCOMClient软件包,如此处Sending email in R via outlook所述。在Outlook 2010和Windows 7上一切正常。该脚本无法正常工作,因为我已将系统更改为带有Outlook 2016的Windows 10。
这是脚本:
library(RDCOMClient)
OutApp <- COMCreate("Outlook.Application")
outMail = OutApp$CreateItem(0)
outMail[["To"]] = "test@test.com"
outMail[["subject"]] = "test"
outMail[["body"]] = "Test."
outMail$Send()
它在最后一行失败,并显示以下错误:
80004004 不支持InterfaceSupportsErrorInfo checkErrorInfo -2147467260 错误:操作中止
建议的解决方法是打开消息框并模拟按Ctrl + Enter:
library(KeyboardSimulator)
library(RDCOMClient)
OutApp <- COMCreate("Outlook.Application")
outMail = OutApp$CreateItem(0)
outMail[["To"]] = "test@test.com"
outMail[["subject"]] = "test"
outMail[["body"]] = "Test."
outMail$Display()
Sys.sleep(3)
keybd.press('Ctrl+Enter')
但是这种方法不是100%可靠的。
您是否知道如何使outMail $ Send()重新工作?
谢谢!