1

我有一个 R 闪亮的应用程序,它根据用户点击的内容生成任何格式的 R 降价报告。每次生成此报告时,我都想通过电子邮件将其发送给自己,我似乎在网上找不到太多关于此的信息。我想知道是否有人知道如何开始

4

2 回答 2

1

如果您使用 Outlook,我建议您使用 RDCOMClient 包。

install.packages(RDCOMClient)
require(RDCOMClient)

OutApp <- COMCreate("Outlook.Application")
outMail = OutApp$CreateItem(0)
outMail[["To"]] = "you@domain.com"
outMail[["subject"]] = "subject here"
outMail[["htmlbody"]] = "email text"
outMail[["Attachments"]]$Add("c:/file.blah")
outMail$Send()
于 2016-12-08T21:42:55.317 回答
0

你可以试试这个mailR包。从mailR github 文档中,您可以发送电子邮件并使用 attach.files 附加相关报告。

library(mailR)
send.mail(from = "sender@gmail.com",
          to = c("recipient1@gmail.com", "recipient2@gmail.com"),
          subject = "Subject of the email",
          body = "Body of the email",
          smtp = list(host.name = "smtp.gmail.com", port = 465, ssl = TRUE,
                      user.name = "gmail_username", passwd = "password"),
          authenticate = TRUE,
          send = TRUE,
          attach.files = c("./download.log"),
          file.names = c("Download log.log"),
          file.descriptions = c("Description for download log"))

sendmailR可以实现类似的结果,但附件是使用mime_part().

library(sendmailR)
from <- 'you@account.com'
to   <- 'recipient@account.com'
subject <- 'Email Subject'
body <- list('Email body text.',
             mime_part(x = 'pathToAttachment', y = 'nameOfAttachment'))
sendmail(from, to, subject, msg = body,
         control = list(smtpServer='ASPMX.L.GOOGLE.COM'))
于 2016-12-08T21:29:56.230 回答