0

I have R Studio version 3.4.3. I'm having a problem sending emails to min 2 people (in the future to over 100 people).

For example: Mail to one person. Here everything is ok. This is code:

library(RDCOMClient)
OutApp <- COMCreate("Outlook.Application")
outMail = OutApp$CreateItem(0)
to="a@outlook.pl"
outMail[["To"]] =to
outMail[["subject"]] = "Mail R Studio"
outMail[["body"]] = "body mail"
outMail$Send()

So, let's send mail to 2 people. I do it this:

mailing_list <- data.frame(to = c('a@outlook.pl','a@outlook.pl'), 
                       subject = c('Mail R Studio','Mail R Studio'), 
                       body = c('Please, help me','Please, help me') 

for (i in 1:nrow(mailing_list)) {
  OutApp <- COMCreate("Outlook.Application")
  outMail = OutApp$CreateItem(0)
  outMail[["To"]] = mailing_list[i,1]
  outMail[["subject"]] = mailing_list[i,2]
  outMail[["body"]] = mailing_list[i,3]
  outMail$Send()
}

Error code:

Error in `[[<-`(`tmp`, "To", value = 1L) :

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, : nie ma pakietu o nazwie ‘RDCOMServer’

But when I install.packages("RDCOMServer") feedback is:

Warning in install.packages :

package ‘RDCOMServer’ is not available (for R version 3.4.3)

Please, help me do that! Thanks

Philipp Maurer
  • 2,480
  • 6
  • 18
  • 25
Madelaine
  • 1
  • 1
  • 1

3 Answers3

0

Example code to send email to multiple users:

library(RDCOMClient)

init com api

OutApp <- COMCreate("Outlook.Application")

create an email

outMail = OutApp$CreateItem(0)

configure email parameter

outMail[["To"]] = paste ( "samikar@cisco.com"
                          ,"subhdas@cisco.com"
                          ,"ragthumm@cisco.com"
                          ,"snarasgo@cisco.com"
                          ,"dmarwaha@cisco.com"
                          ,"shrenaik@cisco.com"
                          ,"ahabdelj@cisco.com"
                          , sep = ";", collapse = NULL)
outMail[["subject"]] = 'subject'

outMail[["body"]] = 'body'

send it

try(outMail$Send())
  • Thanks you! But I have everyday new data frame (here prototype "mailing_list" ) with column "to", where are over 100 mails. I must send emails everyday to other person. So, I wrote a loop to do it faster, because I haven't time to do it with function paste... Can you help me in this way? – Madelaine Aug 06 '18 at 07:43
0

Your data.frame named mailing_list 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

mailing_list <- data.frame(to = c(...), ..., stringsAsFactors = FALSE)
CertainPerformance
  • 356,069
  • 52
  • 309
  • 320
0

Please separate emails with a semi colon (;) in the to list and it should work fine.

Example: to="a@outlook.pl;b@outlook"

Ashish
  • 1