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)?
Related
I have been trying to send mails using blastula and sendgrid.
I tried a couple of options, but login is denied when sending the email:
Error in curl_fetch_memory(smtp_server, handle = h) : Login denied
Blastula01.Rmd
---
title: "Nada 01"
output: blastula::blastula_email
---
## Including Plots
Nada Nada NAda
``` {r pressure, echo=FALSE}
library(ggplot2)
ggplot(mtcars, aes(x=wt, y=mpg)) +
geom_point() +
ggtitle('MPG Nada nada')
blastula01.R
when asked for password (SMTP server password) prompted by the create_smtp_creds_key, I completed with my sendgrid key.
Thanks is advance!
library(blastula)
email_object <- render_email('Blastula01.Rmd')
create_smtp_creds_key(
id = 'Sendgrid',
user='info#xxxx.com',
host = "smtp.sendgrid.net",
port = 465,
use_ssl = TRUE,
overwrite = TRUE
)
smtp_send(email_object,
from = "info#xxxx.com",
to = "yyy#gmail.com",
subject = "Blastula 01 test",
credentials= creds_key("Sendgrid")
)
I have created two tables that I would like to send in body email using R.
Currently I am using mailR package and have managed to send one of the tables, however I can't find a way to include both tables in the email. Please note that the two tables have different number of columns (and so I can't append them). Any suggestions? Thanks
send.mail (from = "email",
to = c("email"),
subject = "Something",
body = print(xtable(tablename), type = "html",
format.args = list(big.mark = ",", decimal.mark = "."),
size="\\fontsize{10pt}\\Arial",
booktabs = TRUE,
include.rownames = FALSE),
html = TRUE,
smtp = list(host.name = "hostname"),
attach.files = c(paste0("G:/",
format(Sys.time(), "%d-%b-%Y"), ".xlsx")),
send = TRUE)
Am unable to send the email through the R, even after less secure apps access allowed (ON).
library(xtable)
library(mailR)
library(sendmailR)
library(rJava)
send.mail(from = "eduru.suresh#swiggy.in",
to = c("suresh.eduru1#gmail.com"),
subject= paste0("Report 1 : Raipur City Performance Metrics"),
body=print(xtable(Raipur,caption = "Raipur City Performance Metrics"),
type="html", caption.placement = "top"),
html = TRUE,
smtp = list(host.name="smtp.gmail.com",port=465,
user.name="xxxxxx#xxxx.in",
passwd="xxxxxxx",ssl=TRUE),
authenticate = TRUE,
send = TRUE)
send.mail(from = "abc#gmail.com",
to = c("abc#gmail.com"),
subject = mail_subject,
body = "High_loss_gain_Imprsn_accounts.html",
html=TRUE,
attach.files = "c:/users/rkathuria/Documents/ACCOUNT_BLOCK_NO_COST_MONITOR.xlsx",
smtp = list(host.name = "aspmx.l.google.com", port = 25),
authenticate = FALSE,
send = TRUE)
In the body part of send.mail; i want to send this html table and a "Hello" message. However, it is either taking my message or html table.
body = "High_loss_gain_Imprsn_accounts.html" ----> this line prints my table in mail message body.
body = "Hello" --> this lines prints Hello.
How can I put together in mail body?
<------------------------------------------------------------------------------->
If instead of xtable, i use tableHTML package and write my code, would it will solve my purpose of adding 2 tables on mail with subject.
mail_body1<-tableHTML(High_loss_gain_Imprsn_accounts, widths = rep(100, 11), caption="Hi, High gain loss account", collapse = 'separate')
mail_body<-paste0(mail_body1,mail_body1)
mail_subject<-paste("Account Block No Cost Monitor ", Sys.Date()-1)
send.mail(from = "abc#gmail.com",
to = c("abc#gmail.com"),
subject = mail_subject,
body = mail_body,
html=TRUE,
attach.files = "c:/users/rkathuria/Documents/ACCOUNT_BLOCK_NO_COST_MONITOR.xlsx",
smtp = list(host.name = "aspmx.l.google.com", port = 25, ssl = TRUE),
authenticate = FALSE,
send = TRUE)
And new problem am facing is through this smtp, mail is not going now.
I struggeled with this before and the best solution I could find was using xtable to produce a html table with caption:
table <- data.frame(a = LETTERS[1:6],
b = LETTERS[7:12])
mailR::send.mail(from = "XXXXXXXX",
to = "XXXXXXXX",
subject = "Hello World",
body = xtable::print.xtable(xtable::xtable(table,
caption = "Hello World"),
type = "html",
caption.placement = "top",
include.rownames = FALSE),
html = TRUE,
smtp = list(host.name = "smtp.gmail.com",
port = 465,
user.name = "XXXXXXXX",
passwd = "XXXXXXXX",
ssl = TRUE),
authenticate = TRUE,
send = TRUE)
The problem is that you can only pass one object or path to body. So if you want to have more than one caption line, you would need to change your html object, I think (I haven't tested what happens if you put more text into the caption, so this might work, too).
I am creating an html output of the dataframe so that the url in one of the column is hyperlinked. Want to embed this in email body instead of attachment, I am using RDCOMclient package.
Forget about RDCOMclient. Try this to e.g. send the data frame df to a gmail account:
library(mailR)
library(xtable)
df <- data.frame(links = sprintf('Go here', c("http://stackoverflow.com/questions/31290427/how-to-embed-a-html-file-in-email-body-using-rdcomclient", "http://stackoverflow.com/")), x = 1:2)
html <- print(xtable(df), type = "html", include.rownames = FALSE, sanitize.text.function = force)
send.mail(from = "...#gmail.com",
to = "...#gmail.com",
subject="subject",
body = html, html = TRUE,
smtp = list(host.name = "smtp.gmail.com", port = 465, user.name = "username", passwd = "password", ssl = TRUE),
authenticate = TRUE,
send = TRUE)
(You may need to allow access to less secure apps.)