【问题标题】:Send email from R using "sendmailR" with more than 1 attachments使用带有多个附件的“sendmailR”从 R 发送电子邮件
【发布时间】:2020-09-29 21:18:13
【问题描述】:

我正在使用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)

【问题讨论】:

    标签: r sendmailr


    【解决方案1】:

    sendmailr支持多个附件;看看这是否能解决您的问题(例如 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)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-09-12
      • 1970-01-01
      • 1970-01-01
      • 2021-09-14
      • 2016-07-04
      • 2012-08-11
      相关资源
      最近更新 更多