使用gmailr发送HTML消息

Jac*_*ase 17 r gmail-api gmailr

我希望能够使用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 <- mime() %>%
 to("you@gmail.com") %>%
 from("me@gmail.com") %>%
 subject("This is a subject") 
test_email$parts <- c(html_body("I wish <b>this</b> was bold"),text_body("plain"))
Run Code Online (Sandbox Code Playgroud) 结果:mime $ parts中的错误:$ operator对原子向量无效

Jan*_*Jan 2

嗯 - 这就是我尝试过的:

library(gmailr)
gmail_auth('mysecret.json', scope = 'compose') 

test_email <- mime() %>%
 to("to@gmail.com") %>%
 from("from@gmail.com") %>%
 subject("This is a subject") %>%
 html_body("<html><body>I wish <b>this</b> was bold</body></html>")
send_message(test_email)
Run Code Online (Sandbox Code Playgroud)

瞧(德语 gmail...)在此输入图像描述

看起来诀窍就是简单地放入真正的 HTML - 包括<html><body>- 让 gmail 理解。