Abhishek Gupta
Abhishek Gupta

Reputation: 161

GmailR Sending data.frame in body of email

I want to send data.frame data in body of email using gmailR. I tried htmlTable for the same. msg = htmlTable(data,rnames=FALSE)

html_bod <- paste0("<p> This is a test email. </p>", msg)

# sending mail
use_secret_file("/Users/abhishekgupta/Downloads/gmailR.json")



msg = htmlTable(data,rnames=FALSE)

html_bod <- paste0("<p> This is a test email. </p>", msg)

# sending mail
use_secret_file("/Users/abhishekgupta/Downloads/gmailR.json")



test_email <- mime(
  To = "[email protected]",
  From = "[email protected]",
  Subject = "Data City Wise",
  body = html_bod,
  html =TRUE)

send_message(test_email)

Upvotes: 2

Views: 1320

Answers (1)

clemens
clemens

Reputation: 6813

You can use html_body() instead of the body argument.

Load the packages:

library(gmailr)
library(tableHTML)

Create an HTML table using tableHTML:

msg = tableHTML(mtcars)

Add a paragraph before the table:

html_bod <- paste0("<p> This is a test email. </p>", msg)

Create a MIME message and send it:

mime() %>%
  to("[email protected]") %>%
  from("[email protected]") %>%
  subject("Data City Wise") %>% 
  html_body(html_bod) %>% 
  send_message()

This is how the email looks like in gmail:

gmail_output

Upvotes: 8

Related Questions