通过 Outlook (RDCOMclient) 将 R Markdown 输出作为正文电子邮件发送 [英] Sending R Markdown output as body email via outlook (RDCOMclient)
问题描述
刚学习 R Markdown 语言,想知道我是否可以通过 Outlook 从 R 发送正文中的输出(使用 RDCOMClient;我的办公室不使用 gmail)
Just learning R Markdown language and wondering if I can send the output in body email via outlook from R (using RDCOMClient; my office don't use gmail)
谢谢
推荐答案
根据 Ben 的回答,到处出现的奇怪符号可能是由 R 和 Outlook 对象(由 RDCOMClient 库创建)之间的编码不匹配引起的.
Building upon Ben's answer, the strange symbols showing up everywhere are probably being caused by a enconding mismatch between R and Outlook Object (created by the RDCOMClient Library).
Outlook 的基本编码是UTF-16",而基本的 RMarkdown 输入是UTF-8".要确保 RMarkdown 生成的 html 输出为UTF-8",请写入:
Outlook's basic encoding is "UTF-16", while the basic RMarkdown input is in "UTF-8". To make sure your html output generated by RMarkdown is in "UTF-8" write:
knitr::knit("tale_email_body.Rmd", encoding = "UTF-8")
eb <- read_lines("tale_email_body.html",locale = locale(encoding = "UTF-8"))
Encoding(eb)
您应该看到一个向量,其条目为 "UTF-8"
或 "unknown"
.接下来您必须使用以下方法将编码转换为正确的格式:
You should see a vector whose entries are "UTF-8"
or "unknown"
. Next you have to convert the encoding to the right format using:
eb2 <- paste(eb, sep="", collapse="")
eb2 <- iconv(eb2, from = "UTF-8",to= "Latin1")
他们应该能够使用 Ben 的代码发送没有奇怪符号的电子邮件:
You should them be able to send emails without strange symbols using Ben's code:
library(RDCOMClient)
olMailItem <- 0
OutApp <- COMCreate("Outlook.Application")
outMail = OutApp$CreateItem(olMailItem)
# this retains default Outlook signature
outMail$GetInspector()
signature <- outMail[["HTMLBody"]]
outMail[["To"]] <- sm
outMail[["CC"]] <- paste("egrp",dm,sep=";")
outMail[["subject"]] <- "note this"
outMail[["BodyFormat"]] <- 2
outMail[["HTMLbody"]] <- paste0(eb2, signature)
outMail$Display()
outMail$Send()
这篇关于通过 Outlook (RDCOMclient) 将 R Markdown 输出作为正文电子邮件发送的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!