Reputation: 329
I want to be able to use the gmailR package to send R-generated HTML reports via email inline(not as attachments). I'm unable to even send a basic HTML email using gmailr
. I've attempted the following unsuccessfully and need some help:
library(gmailr)
gmail_auth("oauth.token.json", scope = "compose")
test_email <- mime() %>%
to("[email protected]") %>%
from("[email protected]") %>%
subject("This is a subject")
test_email$body <- "I wish <b>this</b> was bold"
send_message(test_email)
RESULT: Message successfully sends, but body is plain text - not HTML
Attempt 2
test_email <- mime() %>%
to("[email protected]") %>%
from("[email protected]") %>%
subject("This is a subject") %>%
html_body("I wish <b>this</b> was bold")
test_email$body
RESULT: test_email$body is NULL
Attempt 3
test_email <- mime() %>%
to("[email protected]") %>%
from("[email protected]") %>%
subject("This is a subject")
test_email$body <- html_body("I wish <b>this</b> was bold")
RESULT: Error in mime$parts : $ operator is invalid for atomic vectors
Attempt 4
test_email <- mime() %>%
to("[email protected]") %>%
from("[email protected]") %>%
subject("This is a subject")
test_email$parts <- c(html_body("I wish <b>this</b> was bold"),text_body("plain"))
RESULT: Error in mime$parts : $ operator is invalid for atomic vectors
Upvotes: 17
Views: 3448
Reputation: 13858
Well - this is what I tried:
library(gmailr)
gmail_auth('mysecret.json', scope = 'compose')
test_email <- mime() %>%
to("[email protected]") %>%
from("[email protected]") %>%
subject("This is a subject") %>%
html_body("<html><body>I wish <b>this</b> was bold</body></html>")
send_message(test_email)
Seems like the trick was simply to put in real HTML - including <html>
and <body>
- to make gmail understand.
Upvotes: 2