Using Google Service Accounts for Gmail (sending mail)?

  • Goal: Sending emails using a Google Service Account

  • Steps: Everything to get a service account working with other APIs such as Directory API. I have the scope set up from here

  • Details: Is it possible to use Google Service Accounts to send mail? I get an error about 'precondition failed' and it's similar to this

I found this but I am not sure if they are using Service Accounts.

the raw body is just an encoded String like this

Hi @bhsuarez,

I have a similar setup and think you are close. Try something like this:

{
  "raw": "{{transform.value}}",
  "sendAsEmail": "service@optipath.ca"
}

If that doesn't work, there is a fairly extensive thread here.

Please do let me know. I'm usually around. :slight_smile:

Hm, looks like your auth is set up as OAuth2 and not Google Service account link

I think it's your code. Instead of this: {{transformEmail.value}}

Try this:

{
  "raw": "{{transformEmail.value}}"
}

Unfortunately that doesn't matter. That transform was spitting out {
"raw": "encodedMessage"} anyways

Above you show the Response error. Can you also do a screenshot of the API Request? Here is my test.

Are you using OAuth2 as your authentication for the query?

Yes, OAuth2.

It would help to see both your API Request and your transformEmail.

Otherwise it could be the setup in Google Cloud Console. I may have time over the weekend to replicate. Screenshots of your setup in Google would help.

I made the post stating Google service account doesn’t work. Oauth2 works fine

Yes, I understand what you are trying to do. If you share with screenshots we can likely diagnose and get you going.

@bhsuarez,
Are you using a Google Workspace account? Or is this a personal gmail? Cause if its from a Google Workspace, you need to configure domain-wide delegation from the workspace account to the service account. (Have you done this in the google console?) If it's a personal gmail account you need to use Oauth.

Yes I have it enabled and the correct scope. Are you able to replicate?

@bhsuarez,
Well I THOUGHT I had replicated it because I got the same error as you, but that was with a personal gmail account. I don't have a google workspace set up. I will investigate doing that to see if I can replicate your issue. (I frankly couldn't even do Oauth because google has put restrictions on the gmail scopes and I have to get special permission from google...)