5

I have created an application using Shiny and uploaded to the server that belongs to shinyapps.io; I have tested it and all is fine. My application creates via the server.R a text file that I would like to send to my email when a user finishes performing a task. I want to send that file to my email because I do not see a way in which to see the files that my shiny application outputs in the shinyapps.io admin tool. So bottomline, how can I send a file from a shiny application to my email?

For example if I have the following:

library(sendmailR)
datos<-read.table("data.txt")
to <- "<loretta@gmail.com>"
subject <- "Email Subject"
body <- "Email body."                     
mailControl=list(smtpServer="ASPMX.L.GOOGLE.COM")
sendmail(from="localhost",to=to,subject=subject,msg=body,control=mailControl)
attachmentObject <- mime_part(name=datos)
bodyWithAttachment <- list(body,attachmentObject)
sendmail(from="localhost",to=to,subject=subject,msg=bodyWithAttachment,control=mailControl)

I would like to know what I should put in the from part, I mean I have put it localhost, but I need to put the address of where the shiny application is running; from where I can get that?

Also when I run the above code, not in a Shiny environment, but as a script I got the following error after the sendmail part:

Error in wait_for(code) : 
  SMTP Error: 5.5.2 Syntax error. g22si4860678yhc.87 - gsmtp

any help would be great

Little
  • 3,363
  • 10
  • 45
  • 74
  • have a look here. i think its quite easy to send an email to gmail account from R http://stackoverflow.com/questions/2885660/how-to-send-email-with-attachment-from-r-in-windows – Pork Chop May 15 '15 at 16:34
  • have tried @pops with no luck at all – Little May 17 '15 at 20:53
  • I try a different way. Just create a html using the R file and create a batch to run the R file and attach the html file and send mail. I think you can use it as work around until it works. – Arun Raja May 19 '15 at 08:45
  • Something happened with the sendmailR package and doesnt seem to work anymore. Try with MailR package, you might need to specify the directory of rJava too if you have problems loading it – Pork Chop May 20 '15 at 07:42
  • I understand from your question that you want to send an email because you are not able to save a file. This link explains how to share data across sessions: goo.gl/Aa4bsp The first option, using Amazon S3, has an example (goo.gl/EZgyKZ) that seems pretty easy to implement. If you would like a separate file for each user you could change the name of the .txt in each session (I usually do that by paste0(as.numeric(Sys.time()),".txt")) – Jon Nagra May 22 '15 at 17:58

1 Answers1

0

This works for me for sending email from outlook using the mailR library:

library(mailR)

bodyMsg <- "Some message to be included in the body of the email"

send.mail(from = "sender@xyz.com", to = "receiver@xyz.com",  subject = "Some topic",
              body = bodyMsg ,  authenticate = TRUE, html = TRUE, send = TRUE, attach.files = file.path(folder, fileName),
              smtp = list(host.name = "abcdef.xyz.com", port = 587, user.name = "sender@xyz.com", passwd = "password", tls = TRUE))}
RanonKahn
  • 853
  • 10
  • 34