0

我是使用 Library mailR 的新手,在谷歌上搜索了很多,但找不到任何有用的东西。

我在 R 中有 2 个 html 表,我想在邮件正文中使用 MailR 库发送它们,但是当我发送邮件时,两个表看起来像是相互连接的。

如何使用 MailR 库调整邮件正文。

我想要邮件 看起来像下面提到的格式。

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

在此处输入图像描述

空间

在此处输入图像描述

"some sentence here:

我正在使用代码制作表格,如下所示:

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

和table2的相同代码

要发送电子邮件,代码如下所示:

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

1 回答 1

0

这是一个例子:

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)  

在此处输入图像描述

于 2018-02-26T20:14:29.880 回答