2

sendmailR用来从 R 发送电子邮件。有谁知道需要使用什么才能附加多个文件?

这是我一直用于单个附件的代码,但我不知道如何为多个文件调整它:

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)
4

1 回答 1

0

sendmailr支持多个附件;看看这是否解决了您的问题(例如参考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)
于 2020-09-30T00:01:37.460 回答