-
Notifications
You must be signed in to change notification settings - Fork 55
Description
I did not see this specific issue raised by others so submitting a new issue here.
I am able to use the gmailr library to send emails with no problems locally, using a json file created as a "Desktop App" Application type through the "Create Credentials -> OAuth 2.0 Client IDs" workflow from the Credentials tab on Gmail API.
To confirm, the below works fine locally -
>library(googleCloudStorageR)
>library(gmailr)
SET GCS BUCKET NAME -
> gcs_global_bucket("our_preferred_bucket_name")
Show json file path is correct -
> objects <- gcs_list_objects() # data from the bucket as list
Show JSON file name is correct
> print(objects$name[4])
[1] "file_for_email_sending.json"
> gm_auth_configure(path = "file_for_email_sending.json", email = "my_email_addess.com")
Can create email here -
> test_message <- gm_mime() %>% gm_to("my_email_addess.com") %>% gm_from("my_email_addess.com") %>% gm_subject("blank subject") %>% gm_text_body("blank body")
Email send below works fine locally
> gm_send_message(test_message)
However, the same approach simply will not work for me when I test run an R script using Cloud Build (and googleCloudRunner I should add). When I use the path reference approach shown above, I receive the below error trying to run gm_send_message():
Error: lexical error: invalid char in json text.
file_for_email_sending.j
(right here) ------^
When I try manually specifying the key and secret (client_id and client_secret respectively in the JSON file), I receive the below Gmail API 403 error when I run gm_send_message():
Error in gmailr_POST(c("messages", "send"), user_id, class = "gmail_message", :
Gmail API error: 403
Request had insufficient authentication scopes.
Calls: gm_send_message -> gmailr_POST -> gmailr_query
Execution halted
I would greatly appreciate any pro tips on how to resolve.