Email Unique Attachments to multiple recipients using 'sendmailR'

29 Views Asked by At

I am trying to use the 'sendmailR' library to read a data frame I have made, and then email each recipient their own individual attachment:

library(sendmailR)
library(readxl)

# Read the XLSX file
data <- read_excel("C:/Users/RWALLICK/Desktop/Test_email_list2.xlsx")

# Loop through each row of the data frame
for (i in 1:nrow(data)) {
  from <- ""
  to <- data$Email[i]  
  subject <- "Email with attachment"
  body <- "This is the body of the email."
  
  attachment <- data$Attachments[i]
  
  # Create the email object
  email <- list(from = from,
                to = to,
                subject = subject,
                body = body,
                smtp = list(host.name = "", port = 25, user.name = "", passwd = "", ssl = TRUE),
                attach.files = attachment)
  
  # Send the email
  sendmail(email)
}

I ran this code, and recieved an error: Error in sendmail(email) : 'from' must be a single address.

Any suggestions?

0

There are 0 best solutions below