【问题标题】:How to email an R markdown report in any format (PDF, HTML, WORD) when it is generated?生成时如何以任何格式(PDF、HTML、WORD)通过电子邮件发送 R Markdown 报告?
【发布时间】:2017-04-24 06:08:09
【问题描述】:

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

【问题讨论】:

    标签: html r pdf r-markdown sendmailr


    【解决方案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()
    

    【讨论】:

      【解决方案2】:

      你可以试试mailR 包。从mailR github documentation,您可以发送电子邮件并使用 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'))
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-08-29
        • 2020-04-29
        • 2020-10-13
        • 2015-03-12
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多