Invalid scope, can't get Gmail SMTP token

Issue: OAuth2 Access Token not Being Generated for Gmail

I am trying to use an SMTP library to send mail via Gmail. To do this, I need to generate an OAuth2 access token. I have set up an OAuth2 client account in the Google API console, enabled the Gmail API, and added the scope in the OAuth consent screen setup. However, when I make a POST request to, I get the error invalid_scope. When I switch the scope to email, the request goes through. I have tested this with two different HTTP clients to make sure this wasn’t due to some encoding issue.

What am I doing wrong?

The issue is that you are using the incorrect scope for generating an OAuth2 access token for Gmail. Instead of using the scope, you should use the scope. This should allow you to generate an access token that can be used to send mail via Gmail using SMTP.