r - 使用 For 循环从 R 发送电子邮件?使用 RDCOMClient
问题描述
我目前有 5 个电子表格,我需要将它们分别发送到 5 封电子邮件中。
这是我目前对电子邮件的逻辑:
#Script to send out
attachments <- c('C:/Users/santi/Documents/Cost Changes xlsx/spreadsheet.xlsx') #spreadsheet variable
OutApp <- COMCreate("Outlook.Application")
outMail = OutApp$CreateItem(0)
outMail[["To"]] = paste("john_doe@outlook.com"
, sep=";", collapse=NULL)
outMail[["subject"]] = " Rebate"
outMail[["body"]] = "Hi -
Attached is the spreadsheet
Let me know if you have any questions, thanks.
This is an automated message from RStudio please respond if you find any errors.
"
purrr::map(attachments, ~ outMail[["attachments"]]$Add(.))
outMail$Send()
我将如何迭代它以发送 5 封单独的电子邮件,同时附加相关的电子表格?
解决方案
你还没有描述你的电子表格命名。
SheetNames <- c("sheet1.xls", "sheet2.xls", "sheet3.xls")
PathName <- "C:/Users/santi/Documents/Cost Changes xlsx/"
for (sheet in SheetNames) {
attachments = c(paste0(PathName, sheet))
OutApp <- COMCreate("Outlook.Application")
outMail = OutApp$CreateItem(0)
outMail[["To"]] = paste("john_doe@outlook.com"
, sep=";", collapse=NULL)
outMail[["subject"]] = " Rebate"
outMail[["body"]] = "Hi -
Attached is the spreadsheet
Let me know if you have any questions, thanks.
This is an automated message from RStudio please respond if you find any errors.
"
purrr::map(attachments, ~ outMail[["attachments"]]$Add(.))
outMail$Send()
}
推荐阅读
- c - 为什么必须在 rust 中初始化结构?
- python - 在 pandas 中为每个 groupby 创建具有条件的新数据框
- build - 寻找有关如何为 AST2600 构建 OpenBMC 的说明
- ffmpeg - 如何使用 ffmpeg 将多个视频文件与单个音频文件连接起来?
- hive - 气流找不到直线
- android - 在活动中安排广播和服务
- php - 不知道如何从 MySql Query 中获取数据
- c++ - 由于没有运算符“<<”与这些操作数匹配,程序无法运行
- html - Angular 9 Keyvalues 管道不是为生产而构建的
- javascript - 按下按钮后在 React 中进行 AJAX 调用?