【问题标题】:How to send mails from outlook using R RDCOMClient using latest Version?如何使用 R RDCOMClient 使用最新版本从 Outlook 发送邮件?
【发布时间】:2017-08-15 18:45:40
【问题描述】:

当我使用最新版本的 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"]] = "some@outlook.com"
    outMail[["CC"]] <- "Some@outlook.com"
    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"]] = "some@outlook.com"
Error in `[[<-`(`*tmp*`, "To", value = "some@outlook.com") : 
  [[<- defined for objects of type "S4" only for subclasses of environment

【问题讨论】:

    标签: r email outlook shiny


    【解决方案1】:

    我认为下面的代码应该适合你。您可能必须像我所做的那样单独定义电子邮件的body,然后将其粘贴到outMail[["HTMLbody"]] = paste0("&lt;p&gt;", body, "&lt;/p&gt;", 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"]] = "test@test.com"
    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()
    

    【讨论】:

      猜你喜欢
      • 2015-08-10
      • 2019-10-15
      • 1970-01-01
      • 2017-07-23
      • 1970-01-01
      • 1970-01-01
      • 2018-09-01
      • 2023-04-06
      • 2019-03-09
      相关资源
      最近更新 更多