我希望能够使用gmailR包通过内联电子邮件(而不是附件)发送R生成的HTML报告.我甚至无法使用发送基本的HTML电子邮件gmailr.我尝试了下面的失败并需要一些帮助:
library(gmailr)
gmail_auth("oauth.token.json", scope = "compose")
test_email <- mime() %>%
to("you@gmail.com") %>%
from("me@gmail.com") %>%
subject("This is a subject")
test_email$body <- "I wish <b>this</b> was bold"
send_message(test_email)
Run Code Online (Sandbox Code Playgroud)
结果:消息成功发送,但正文是纯文本 - 而不是HTML
尝试2
test_email <- mime() %>%
to("you@gmail.com") %>%
from("me@gmail.com") %>%
subject("This is a subject") %>%
html_body("I wish <b>this</b> was bold")
test_email$body
Run Code Online (Sandbox Code Playgroud)
结果:test_email $ body为NULL
尝试3
test_email <- mime() %>%
to("you@gmail.com") %>%
from("me@gmail.com") %>%
subject("This is a subject")
test_email$body <- html_body("I wish <b>this</b> was bold")
Run Code Online (Sandbox Code Playgroud)
结果:mime $ parts中的错误:$ operator对原子向量无效
尝试4
test_email …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用SendMailR发送数据帧.我可以将它作为附件发送,格式相当合理.但是,我想在电子邮件正文中发送数据帧.我尝试了capture.output,print,sprintf,但我甚至无法将格式关闭.
例如,我尝试了以下语法
for (i in 1:nrow(df)){
MSG = c(MSG,rownames(df)[1],as.character(unlist(df[i,])),'\n')
}
MSG = sprintf('%-10s',MSG)
sendmail(from,to,subject,msg = list(MSG,attachment1,attachment2 ... ))
Run Code Online (Sandbox Code Playgroud)
换句话说,我认为可能需要将我的数据帧转换为带有/ n和sprintf('s-10%')等的格式并将其存储在MSG中.有人能指出我正确的方向吗?