0

I have tried this code several different ways and keep getting the same error. I don't believe the code is the issue, I'm wondering if there is a functionality of RDCOMClient I am missing. The functionality works, as I have sent many emails through this. It is the looping functionality that is not working.

I am simply trying to loop through a vector of a DataFrame and send out an email corresponding to the email it is looping over.

(e.g., an email should be sent to email1, an email should be sent to email2, etc.)

test.df <- data.frame(
                      "email" = c("email1", "email2", "email3")
                      ,"name" = c("name1", "name2", "name3")
                      )
mail_fun <- function(mail) {
  outMail = OutApp$CreateItem(0)
  ## configure  email parameter
  outMail[["To"]] = mail
  outMail[["subject"]] = "Project hours for next week"
  outMail[["HTMLBody"]] = paste0("<p>Testing sending hours through R</>")
  ## send it
  outMail$Send()
}

sapply(test.df$email, mail_fun)

This is the error I am receiving:

Error in [[<-(*tmp*, "To", value = 2L) : Can't attach the RDCOMServer package needed to create a generic COM object In addition: Warning message: In library(package, lib.loc = lib.loc, character.only = TRUE, logical.return = TRUE, :

Error in [[<-(*tmp*, "To", value = 2L) : Can't attach the RDCOMServer package needed to create a generic COM object

Felix T.
  • 520
  • 3
  • 11

1 Answers1

0

The data.frame named test.df contains factors, not strings. So you are assigning a value from a factor to outMail[["To"]]. That value is an integer, in this case 1L. So that is wrong. As the answer above says, make these strings. Use:

test.df <- data.frame(to = c(...), ..., stringsAsFactors = FALSE)