2

I am testing dygraphs, what I would like is generate an html file and then send it in an email so outlook can open it and I see the content in the body (NOT just attachment)

This is an extension of this post

Here is dygraphs.Rmd

---
output:
  html_document:
    fig_width: 6
    fig_height: 4
    self_contained: no
---

```{r}
require(dygraphs)
dygraph(nhtemp, main = "New Haven Temperatures", ylab = "Temp (F)") 
```

The following code works and send the email (dygraphs.r)

library(dygraphs)
library(mailR)
library(rmarkdown)

send <- function(subject, body){
  send.mail(from = "me",
            to = "me",
            subject = subject,
            html = T,
            inline = T,
            body = body,
            smtp = list(host.name = "smtp.gmail.com", port = 465, user.name = "me", passwd = "pwd", ssl = T),
            authenticate = T,
            send = T)
}

knitr::knit2html(input='dygraphs.Rmd', output='dygraphs_knitr.html',options = "")
rmarkdown::render('dygraphs.Rmd','html_document','dygraphs_rmarkdown.html')
send('dygraphs_knitr', 'dygraphs_knitr.html')
send('dygraphs_rmarkdown', 'dygraphs_rmarkdown.html')

I doing this I receive the email but the graph is not rendered. Is there a workaround (if this is possible)?

Community
  • 1
  • 1
statquant
  • 13,672
  • 21
  • 91
  • 162
  • 3
    If I got such an email, my hope would be that it _should_ fail or at least be flagged as a security threat. The notion that an email should be able to initiate (or worse, hijack a running) R process seems most unwise. – IRTFM Jan 09 '16 at 16:54
  • 1
    I once tried pretty hard to even get markdown-generated html mail to work in Outlook. And I gave up: creating the html is easy, creating the email body and sending it is easy (given eg some Python libraries) -- and it can be rendered on various mail readers on phones (iOS, Android), desktops (Thunderbird, ...) but NOT on Outlook. By design. Of Outlook. – Dirk Eddelbuettel Jan 09 '16 at 17:26
  • It's possible that I misunderstood the intended workflow. It appeared from the sketchy description and code that you intended a portion of the email to spawn an R process. – IRTFM Jan 09 '16 at 17:32
  • @DirkEddelbuettel You might want to try again, I send myself on outlook markdown V2 rendered by rmardown without issue. – statquant Jan 09 '16 at 19:55
  • I'll try to remember to revisit. We can do this via private email---my last attempt may have been with Office 2007. And just to clarify: html email body, not attachment, showing html formatting directly without having to open anything? The other mail readers did, Outlook did not and I have a colleague go deeply into MSDN discovering a design 'choice'. For safety. Don't even ... – Dirk Eddelbuettel Jan 09 '16 at 20:17
  • @DirkEddelbuettel: Following http://stackoverflow.com/questions/34230391/how-to-send-r-markdown-report-in-body-of-email?rq=1 and sending to my company email works. I see the table and plot within the body. Only "pb" is that it ships the .js files too. Likely you forgot to include the mandatory yaml at the top. – statquant Jan 09 '16 at 20:23
  • Maybe you missed the parts where I said (twice, no less) that it _absolutely worked in all other mail readers but not Outlook_ so I am not sure why you infer that my html was borked or incomplete... – Dirk Eddelbuettel Jan 09 '16 at 20:25
  • 1
    For Pete's sake my html file was fine. – Dirk Eddelbuettel Jan 09 '16 at 20:29
  • @DirkEddelbuettel Because self_contained: no is mandatory for rmarkdown not knitr, and it's the only not trivial thing to make it work. – statquant Jan 09 '16 at 20:34
  • 2
    You are obsessing over Markdown. I am referring to an inability to render any embedded html. Which may be lifted by the newest Outlook version--don't know, and no longer care. I no longer work on a system where Outlook would be the mail client so ... Your bigger problem may well be with triggering execution from email---which with the two decades of spam and fishing is probably turned off everywhere. Just deploy eg via Shiny. – Dirk Eddelbuettel Jan 09 '16 at 20:44

0 Answers0