1

I have an R shiny application that generates an R markdown report in any format depending on what the user clicks. I want to email this report to myself every time it is generated I seem to not find much about this online. I wondering if anyone has any idea how to start this

Maurely
  • 35
  • 2
  • 10

2 Answers2

1

You could try the mailR package. From the mailR github documentation, you can send an email and use attach.files to attach the relevant report.

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 can achieve a similar result but the attachment is added to the body of the email using 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'))
Ben Fasoli
  • 526
  • 3
  • 7
1

If you use Outlook, I'd recommend the RDCOMClient package.

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()
Khaynes
  • 1,976
  • 2
  • 15
  • 27