I am attempting to use the gmailr package in a virtual (hosted) R Studio environment. I have created a service account, enabled the GMail API, and downloaded the client_secret.json file with Oauth credentials which works with the Google Drive and Google Sheets APIs. I also have an API Key stored as an environment variable.

I have tried the following:

library(gmailr)

gm_auth_configure(
  secret="client_secret.json",
  key=Sys.getenv("GOOGLE_API_KEY")
)

gm_auth(
  email = gargle::gargle_oauth_email(),
  path = "client_secret.json",
  scopes = "full",
  cache = gargle::gargle_oauth_cache(),
  use_oob = gargle::gargle_oob_default(),
  token = NULL
)

text_msg <- gm_mime() %>%
  gm_to("[email protected]") %>%
  gm_from("[email protected]") %>%
  gm_text_body("Gmailr is a very handy package!")

gm_send_message(text_msg)

I get the following error: Error in gmailr_POST(c("messages", "send"), user_id, class = "gmail_message", : Gmail API error: 400 Precondition check failed.

I have tried troubleshooting using the steps outlined here: https://cran.r-project.org/web/packages/gmailr/vignettes/sending_messages.html, but nothing seems to work. Any suggestions to get it working would be much appreciated. Thanks!

0

There are 0 best solutions below