2

I am using sendmailR to send emails from R. Does any one know what needs to be used to be able to attach more than one file?

This is the code that I have been using for a single attachment, but I don’t know how to adjust it for more than one file:

library(sendmailR)

from <- "......org"
to <- c("Pegah@...net")
subject <- "Daily Report"
body <- "Attached is today's Daily Report"

mailControl = list(smtpServer=".....net")
attachmentPath <- paste0("/Rate and Lab Counts ", Sys.Date(), ".png")
attachmentObject <- mime_part(x=attachmentPath, name=attachmentName)
bodyWithAttachment <- list(body,attachmentObject)

sendmail(from=from, to=to, subject=subject, msg=bodyWithAttachment, control=mailControl)
ib.
  • 27,830
  • 11
  • 80
  • 100
Pegah
  • 53
  • 1
  • 1
  • 4

1 Answers1

0

sendmailr supports multiple attachments; see if this solves your problem (e.g. ref https://stackoverflow.com/a/14376117/12957340):

library(sendmailR)
from <- "......org"
to <- c("Pegah@...net")
subject <- "Daily Report"
body <- "Attached is today's Daily Report"
mailControl=list(smtpServer=".....net")
attachmentPath_1 <- paste0("/Rate and Lab Counts ", Sys.Date(), ".png")
attachmentPath_2 <- paste0("/Percent change over time ", Sys.Date(), ".png")
attachmentPath_etc <- paste0("/Frequency trend data etc ", Sys.Date(), ".png")
attachmentObject_1 <- mime_part(x=attachmentPath_1, name=attachmentName_1)
attachmentObject_2 <- mime_part(x=attachmentPath_2, name=attachmentName_2)
attachmentObject_etc <- mime_part(x=attachmentPath_etc, name=attachmentName_3)
bodyWithAttachment <- list(body, attachmentObject_1, attachmentObject_2, attachmentObject_etc)
sendmail(from=from, to=to, subject=subject, msg=bodyWithAttachment, control=mailControl)
jared_mamrot
  • 22,354
  • 4
  • 21
  • 46