Send R Markdown output as organizer email through Outlook (RDCOMclient)

Just learning the R Markdown language and wondering if I can send the result in body email via Outlook from R (using RDCOMClient, my office does not use gmail)

thank

+4
source share
1 answer

Short answer:

Create a .Rhtml file for the email body.

Knit it and read:

knitr::knit("tale_email_body.Rhtml")  
library("readr", lib.loc="~/R/win-library/3.2")
eb <- read_lines("tale_email_body.html",n_max= -1L)
eb2<-paste(eb, sep="", collapse="") 

Use the results in the body of the letter:

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

Let me know if you have any questions or improvements.

Partial Credit: How to add my Outlook email signature to a COM object using RDCOMClient

0

Source: https://habr.com/ru/post/1658805/


All Articles