当我使用最新版本的 R RDCOMClient 包发送 Outlook 电子邮件时,它显示错误:
“[[
相同的代码:
library(RDCOMClient)
## init com api
OutApp <- COMCreate("Outlook.Application")
## create an email
outMail = OutApp$CreateItem(0)
outMail$GetInspector()
signature = outMail[["HTMLBody"]]
## configure email parameter
outMail[["To"]] = "[email protected] /cdn-cgi/l/email-protection"
outMail[["CC"]] <- "[email protected] /cdn-cgi/l/email-protection"
outMail[["subject"]] = "some subject"
outMail[["body"]] = "some body"
outMail[["Attachments"]]$Add("C:\\Users\\Some\\Desktop\\file.csv")
outMail[["HTMLBody"]] = paste0('<p>some body', signature, '</p>')
## send it
outMail$Send()
**Error:**
signature = outMail[["HTMLBody"]]
Error in mget(plabels[hasSubclass], env) : invalid first argument
## configure email parameter
outMail[["To"]] = "[email protected] /cdn-cgi/l/email-protection"
Error in `[[<-`(`*tmp*`, "To", value = "[email protected] /cdn-cgi/l/email-protection") :
[[<- defined for objects of type "S4" only for subclasses of environment
我认为下面的代码应该适合你。您可能需要定义body
像我一样分开电子邮件,然后将其粘贴到outMail[["HTMLbody"]] = paste0("<p>", body, "</p>", Signature)
如下所示。如果您已经安装了此代码,则可以正常工作,不会出现任何错误RDCOMClient
包裹。我已经使用最新版本的 R (V3.4.2)、RDCOMClient 和 RStudio 测试了此代码。让我知道这是否对您有帮助。
library(RDCOMClient)
OutApp <- COMCreate("Outlook.Application")
outMail = OutApp$CreateItem(0)
# Get signature from outlook
# GetInspector renders the message in html format.
# Note that if you have not created any signatures, this will return blank
outMail$GetInspector()
Signature <- outMail[["HTMLbody"]]
# Define the body of you email separately
body <- "Define your body here."
outMail[["To"]] = "[email protected] /cdn-cgi/l/email-protection"
outMail[["subject"]] = "TEST EMAIL"
# Paste the body and signatures into the email body
outMail[["HTMLbody"]] = paste0("<p>", body, "</p>", Signature)
# Add your attachment
outMail[["Attachments"]]$Add("C:\\Users\\Some\\Desktop\\file.csv")
outMail$Send()
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)