それマグで!

知識はカップより、マグでゆっくり頂きます。 takuya_1stのブログ

習慣に早くから配慮した者は、 おそらく人生の実りも大きい。

サービスアカウントでGmailアクセスできない?

XOAUTH2も、アプリパスワードもめんどくさいので、サービスアカウントをアカウントを作ってGmailのアクセスを試みた。

あれこれ、ためしたけど、無理っぽいなぁ。普通にWEBアプリとして自分のアプリで自分をOAuthするしかなさそう。

他にもいろいろな人が試みたり、調べたりしているが、Google のサービス・アカウントの機能で、GmailAPIアクセスはできない。Gmail.sendだけでもさせてくれればいいのに・・・

Service accounts cannot access @gmail.com mailboxes. You must use one of the other supported OAuth 2.0 authorization scenarios described at https://developers.google.com/identity/protocols/OAuth2.

https://stackoverflow.com/questions/39510514/gmail-api-service-account

The short answer is no, it's not possible to perform service-account impersonate of a @gmail.com account. The key reason is that although the service account OAuth flow doesn't involve an authorization screen, at the end of the day someone must still say "I authorize this application to impersonate this user."

Now for a while there was a trick where you could take an @gmail.com user through the regular 3-legged flow, and once they approved it use the service account flow from then on. This lead to some strange problems however, so we've disabled that option. This may be why there was disagreement in the past about if this is possible.

https://stackoverflow.com/questions/39510138/google-oauth2-impersonate-service-account-with-usergmail-com/39534420#39534420

参考資料