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
You can send HTML email in Gmail. But, in the past you would have to design the email, get someone to build it, and then manipulate Gmail code to add it. Now you can create and send HTML email in Gmail by dragging, dropping and a click.
The most important thing to know about HTML email is that you can't just attach an HTML file and a bunch of images to a message, then click send. Most of the time, your recipient's email application will break all the paths to your image files by moving your images into temporary folders on the recipient's hard drive.
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)
And voila (German gmail...)
Seems like the trick was simply to put in real HTML - including <html>
and <body>
- to make gmail understand.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With