我有一个R代码,在完成一系列步骤后,最后会发送一封电子邮件。当我在RStudio上运行它时,整个代码运行正常并发送电子邮件。但是,当我通过Windows任务计划程序运行时,代码仍然正常运行(并按预期执行)但不发送电子邮件。我已经尝试了RDCOMClient和sendmailR,问题仍然存在。
以下是任务的安排方式。
程序/脚本:" C:\ Program Files \ R \ R-3.1.3 \ bin \ x64 \ Rscript.exe" 添加参数:datavalv3.R 开始于:C:\ BLP \ Projects \ Project_07
以下是电子邮件的代码部分(使用RDCOMClient)
library(RDCOMClient)
path_name <- file.path(mainDir, subDir)
subject <- paste0("Data quality checks completed for ", analysis_date)
body <- paste0("Data summary has been compiled for all the farms for ", analysis_date,". All the data summaries are saved in the folder <", path_name, ">.")
email_fn <- function(recipient) {
OutApp <- COMCreate("Outlook.Application")
outMail = OutApp$CreateItem(0)
outMail[["To"]] = recipient
outMail[["subject"]] = subject
outMail[["body"]] = body
outMail$Send()
}
email_fn(recipient = "person1@abc.com")
以下是电子邮件的代码部分(使用sendmailR)
library(sendmailR)
from <- "person1@abc.com"
to <- c("person2@abc.com","person3@abc.com")
subject <- "Email Subject"
body <- "Email body."
mailControl = list(smtpServer = "tucson.websitewelcome.com")
sendmail(from = from, to = to, subject = subject, msg = body, control = mailControl)
知道可能是什么问题吗?
这是一个更新:找出问题所在。在任务调度程序安全选项中,早先我已经检查过&#34;运行用户是否登录&#34;。我取消选中此项并检查&#34;仅在用户登录时运行&#34; - 这就行了,电子邮件正在通过。
答案 0 :(得分:0)
当您尝试通过Task Scheduler发送电子邮件时,由于某种原因(不确定原因)而只是跳过了该电子邮件部分。 这是诀窍,请尝试使用 taskscheduleR 软件包。即使您注销,它也会发送电子邮件。请同时安装其他相关软件包。
install.packages('data.table')
install.packages('knitr')
install.packages('miniUI')
install.packages('shiny')
install.packages("taskscheduleR", repos = "http://www.datatailor.be/rcube", type = "source")