0

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?

  • Are you hiding your real email address from us in `from` (understandable) or are you really trying to use an empty string for that field? If so, what is `length(from)`? – r2evans Jul 13 '23 at 20:26

0 Answers0