1

I have to use my google account for gmail and drive services. For drive services now i am using an service account but i cant find any possibility for send emails by service account. Can i login to my account by google api php only using code? I have registered in db my token && refresh_token, in any moment i could use it.

Linda Lawton - DaImTo
  • 106,405
  • 32
  • 180
  • 449
Dmytro V
  • 179
  • 1
  • 7
  • Don't think so - see https://stackoverflow.com/questions/33233694/gmail-api-can-i-send-email-using-the-service-account. One alternative is to use SMTP and log into your personal account that way using an App Password. Or use something like SendGrid etc as mentioned in that link. – ADyson Jul 14 '22 at 15:30
  • I thought this for the last possibility, thank you! – Dmytro V Jul 15 '22 at 06:15

1 Answers1

2

Gmail api does support service accounts, the only issue is that it only works with google workspace gmail accounts, you need to set up domain wide delegation on a workspace account to allow the service account to delignate as a user on the domain.

If you are only accessing your own account you can use Oauth2 and just store the refresh token, your app can just continue to use that to request a new access token whenever it needs.

Another option would be to go though the Gmail smtp server instead, using an apps password.

Linda Lawton - DaImTo
  • 106,405
  • 32
  • 180
  • 449
  • About gmail api for service account ok... but i need to send emails from standard account automatically without interactions, in an programmed operation. Can i just create an $client and set and valid token for using the api or the service needs some cookies ? – Dmytro V Jul 15 '22 at 06:14
  • With standard google gmail accounts, you dont have a choice someone is going to have to authorize it at least once using Oauth2. You dont need cookies you just need to store the refresh token in your app somewhere. I normally just store it in a file . – Linda Lawton - DaImTo Jul 15 '22 at 09:24