0

I have a database in R with a list of email addresses (several on each row). I would like to be able to send a template email to each row with some varying elements in the text (name, action required).

I was thinking to use a function with the RDCOMClient package. As I do not have any code to provide, there is no need to reply with a code, just ideas of how I could solve this problem.

Hack-R
  • 22,422
  • 14
  • 75
  • 131
  • `OutApp <- COMCreate("Outlook.Application"); outMail <- OutApp$CreateItem(0); outMail[["To"]] = paste([VECTOR OF EMAILS HERE], collapse = ';')` – IceCreamToucan Jul 16 '18 at 16:53

2 Answers2

0

In your case you could either

  1. modify this to run inside of a loop that runs on each row of your database/data.frame or
  2. Just put all the emails into to = c()

    pacman::p_load(mailR)
    send.mail(from = "Some Name <whatever@address.net>",
          to = c( "user.email@goes_here.net", "another@address.net"),
          subject="Scoring Completed!",
          body = "This is the answer to your question!!",
          smtp = list(host.name = "host.domain", port = 25),
          authenticate = FALSE,
          send = TRUE)
    

I am sure you can do it with the library you mentioned, but that 1 is very old and not on CRAN, so maybe you'd prefer to use mailR or gmailR anyway.

Hack-R
  • 22,422
  • 14
  • 75
  • 131
0

This may be a good start for you.

library(RDCOMClient)
## init com api
OutApp <- COMCreate("Outlook.Application")
## create an email 
outMail = OutApp$CreateItem(0)
## configure  email parameter 
outMail[["To"]] = "receiver@gmail.com"
outMail[["subject"]] = "some subject"
outMail[["body"]] = "some body"
## send it                     
outMail$Send()

I just tested it and it works fine for me.

ASH
  • 20,759
  • 19
  • 87
  • 200