Unable to send the Emails from the R - 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)

Related

Send tables via email using R

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)

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

Send Email from R with body as integers or list

finlist <- 1:10
library(mailR)
sender <- "SENDER#gmail.com"
recipients <- c("Recipent#gmail.com")
send.mail(from = sender,
to = recipients,
subject="From R",
body = finlist,
smtp = list(host.name = "smtp.gmail.com", port = 465,
user.name="SENDER#gmail.com", passwd="Password", ssl=TRUE),
authenticate = TRUE,
send = TRUE)
The above should send out an Email with subject body as 1, 2, 3, ...10.
However the following error is received.
Error in file.exists(body) : invalid 'file' argument
try
body =paste(finlist, collapse = ",")

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