Sendgrid and Blastula - r

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")
)

Related

How to suppress downloading progress in HTML file

I am using imfr package to download some IMF data series
library(imfr)
t <- imf_data(database_id = "BOP", indicator = "BCA_BP6_USD",
country = "all", start = "1990", freq = "Q")
I prespecified certain parameters in a separate chunk before to suppress downloading progress
knitr::opts_chunk$set(echo = FALSE, message = FALSE, warning = FALSE, error = FALSE, results = 'hide', fig.keep = 'all')
However, neither of these options did the job. Moreover results = 'hide' suppressed all the output including text and figures.
How can I solve this issue without having a separate chunk for data downloading?
You can capture all those downloads message and progress bar in capture.output and wrap it with invisible. (Got this idea from this question and answer on SO).
And then make a wrapper function imf_data which works the same (mask the imfr::imf_data function) but does not print all those download messages and the progress bar.
---
title: "IMF Data"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE, warning = FALSE, message = FALSE)
imf_data <- function(...) {
invisible(capture.output(dt <- imfr::imf_data(...)))
return(dt)
}
```
```{r}
library(imfr)
t <- imf_data(database_id = "BOP", indicator = "BCA_BP6_USD",
country = "all", start = "1990", freq = "Q")
```
```{r, comment=""}
head(t)
```

Unable to send the Emails from the R

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 text message and html table both as message body using mailr package in R

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).

How can I embeded an interactive chart in an email body

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)?

How to embed a html file in email body using RDCOMClient

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.)

Resources