0

I am new to using Library mailR and search a lot on google but couldn't found anything useful.

I have 2 html table in R, i want to sent them using MailR library in mail body but when i'm sending the mail both table looks like joined to each other.

How to tweak mail body using MailR library.

I want mail Looks like below mentioned format.

Hi Team,
"some sentence here" using t.start and nrows() in the sentence

enter image description here

space

enter image description here

"some sentence here:

I am using the code to make table something like this:

Table1<-DF%>% tableHTML(rownames = FALSE,
                      widths = rep(100, 13),
                      second_headers = list(c(1, 6, 6),
                                            c("", "ABC", "XYX")),
                      caption = "ABC Stat") %>%
  add_css_caption(css = list(c("font-weight", "border"),
                             c("bold", "1px solid black")))%>% add_css_row(css = list(c("background-color"), c("lightblue")), rows = 0:2)%>%add_css_caption(css = list(c("background-color"), c("lightblue")))

and same code for table2

And to send e-mail the code looks like:

library(mailR)
sender<-"a12db@gmail.com"


recipients<-c("xyc@gmail.com")

sm<-list(host.name = "smmm.gmail.com", port = 123,
         user.name="a12db@gmail.com",
         passwd="1#4$12#", ssl=TRUE)

send.mail(from=sender,
          to=recipients,
          subject = paste0("Abc Repo"),
          body = paste("Some sentence",Table1,"\br",Table2),
          html = TRUE,
          inline = FALSE,
          smtp = sm,
          authenticate = TRUE,
          attach.files =("abc.csv") ,
          send = TRUE )
Stephen Docy
  • 4,738
  • 7
  • 18
  • 31
Roy1245
  • 507
  • 4
  • 18

1 Answers1

0

Here's an example:

paragraphs <- list(
  glue::glue("Some sentence with {nrow(iris)}:"),
  tab1 = iris[1:3,1:3],
  tab2 = iris[1:3,3:5],
  glue::glue("And another sentence")
)
html <- do.call(paste, c(lapply(paragraphs, knitr::kable, format = "html"), list(sep="<br>")))
smtp <- list(
  host.name = "smtp.gmail.com", 
  port = 465, 
  user.name = "....", 
  passwd = "...", 
  ssl = TRUE
)
from <- to <- "....."
library(mailR)
send.mail(from = from,
          to = to,
          subject = "Report",
          html = TRUE,
          body = html,
          smtp = smtp,
          authenticate = TRUE,
          send = TRUE)  

enter image description here

lukeA
  • 53,097
  • 5
  • 97
  • 100
  • @Roy1245 I am sry. – lukeA Feb 26 '18 at 20:27
  • @IukeA it's okay. – Roy1245 Feb 26 '18 at 20:29
  • I have already converted both the table in `htmltable` format, can you help me with that how to paste it in mail body with one space distance. – Roy1245 Feb 26 '18 at 20:31
  • @Roy1245 `paste("Some sentence",Table1,Table2,sep="
    ")`?
    – lukeA Feb 26 '18 at 20:33
  • 1
    @Roy1245 Please edit your question and provide a [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example/28481250#28481250) as asked by the R tag (hover over it). Otherwise everything will be guess work. You code is missing `DF`, the required packages etc. – lukeA Feb 26 '18 at 20:54
  • Required Package is `mailR` as I have mentioned in question and DF same as `Table1`. – Roy1245 Feb 26 '18 at 20:56
  • 1
    @Roy1245 Again, please *READ* the information behind the link I provided, and feel free to come back with a proper example. – lukeA Feb 26 '18 at 21:07