Настройка flextable и вложение файлов для электронной почты - PullRequest
0 голосов
/ 23 февраля 2019

Что касается моего предыдущего вопроса, Отправить электронное письмо с фреймом данных в качестве гибкого Я хочу добавить несколько битов к этому вопросу.

Вот набор данных:

samplemondata<-structure(list(Root.Cause = c("Blocking", "Created in Error", 
"Duplicate", "Horizontal liquid bottle", "Overhanging", "Title Not Facing  Out", 
"Trash in the Bin", "Units Not Stowed Securely", "Unorganized", 
"Wrong Bin Type"), BCN1 = c("109", "", "", "", "", "70", "", 
"7", "1", "6"), FCO1 = c("98", "1", "", "1", "", "31", "4", "4", 
"", "4"), FRA7 = c("401", "", "", "", "2", "260", "", "2", "", 
"100"), HAM2 = c("414", "", "", "", "1", "115", "", "1", "1", 
"44"), LCY2 = c("230", "", "", "1", "1", "102", "", "3", "", 
"15"), LTN4 = c("30", "", "", "", "", "7", "", "", "", ""), MAN1 = c("66", 
"", "", "", "1", "22", "3", "1", "", "3"), MAN2 = c("104", "", 
"", "", "", "50", "", "2", "", "12"), MAN3 = c("92", "", "", 
"1", "", "36", "", "1", "", "5"), SZZ1 = c("344", "", "", "", 
"2", "114", "1", "15", "", "10")), row.names = c(NA, -10L), class = "data.frame")

А вот код:

library(sendmailR)
library(dplyr)
library(flextable)


ft<-flextable(samplemondata)
ft<-theme_vanilla(ft)
ft<-bg(ft,bg="black",part="header")
ft<-color(ft,color="white",part="header")
ft <- color(ft,  i = ~ samplemondata$BCN1>50 , color = "orange")




msgJP <- try(mime_part(paste0('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
                           Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
                           <html xmlns="http://www.w3.org/1999/xhtml">
                           <head>
                           <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
                           <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
                           <title>HTML demo</title>
                           <style type="text/css">
                           </style>
                           </head>  
                           <body>',"hello,<br>","check out the data for self audit.","<br>",format(ft,type='html'),'</body>
                           </html>')))


 msgJP[["headers"]][["Content-Type"]] <- "text/html"

 body    <- list(msgJP)
 attachmentPath <- "filepath/name.csv"
 attachmentName<- "myname.csv"

 attachmentObject <- mime_part(x=attachmentPath ,name=attachmentName)
 bodyWithAttachment <- list(body,attachmentObject)

from <- "abc@xyz.com"
to<-c("abc@xyz.com")
subject <- paste0("Let this work")

sendmail(from, to, subject, bodyWithAttachment , control = list  (smtpServer="smtp.amazon.com"))

Я хочу отправить фрейм данных в виде гибкого файла, как тело этого письма, вместе с вложением электронной почты.Но сейчас я могу отправить через вложение электронной почты.В электронном письме никто не сталкивается.

Буду признателен за любую помощь.спасибо.

1 Ответ

0 голосов
/ 24 февраля 2019

В своем коде вы допустили ошибку, вы написали

body    <- list(msgJP)
# ...
bodyWithAttachment <- list(body,attachmentObject)

аргумент msg в функции sendmail ожидает список значений MIME, а не список списка, поэтому вы должны написать вместо этого:

bodyWithAttachment <- list(msgJP,attachmentObject)
...