gmail sendgmail configuration for git send-email

From May 30, 2022:

Google no longer supports the use of third-party apps or devices which ask you to sign in to your Google Account using only your username and password.

This is a problem for various applications including git send-email. sendgmail is tool from Google written in go which allows to use OAuth2 credentials.

Using sendgmail requires certain configuration in Google Cloud, download JSON with configuration and rename to ~/.sendgmail.json and then run once:

$ GOPATH/bin/sendgmail -setup

1. Ensure that you are logged in as in your browser.

2. Open the following link and authorise sendgmail:

3. Enter the authorisation code:

My ~/.sendgmail.json contains redirect_uris":["http://localhost"], therefore clicked website is redirected to localhost (no webserver is on my machine) and I don’t get the authorisation code. Could anybody explain what exactly to do in Google Cloud setup to get it working?

Asked By: pevik


Setup the Workspace by following these steps.

Enable the Gmail API on the project.

Setup the OAuth Consent Page.

  • I’m not sure if you can get past not having an authorized domain. I included one I own (and use for a different Google OAuth workflow)
  • Ensure the Gmail API ../auth/gmail.send scope is allowed, nothing else seems required.
  • Include yourself as a registered test user.

Create Credentials.

  • Type: OAuth Client ID
  • Application Type: Desktop App (others may work, just following linked guidance)

Install the sendgmail go package: go install

Run the setup command as you’ve included.

Follow the instructions to authenticate and be redirected to the non-functional page (due to the redirect_uri being localhost.)

The authorization code you need to enter in the prompt can be scraped from the URL for that non-functional redirect.

Here is a example of the URL, you’ll need the value of code GET parameter (i.e. the entire string after code= and before &scope):


The tool doesn’t seem to output anything after submitting the authorization code, however testing sending a patch file to myself was successful with:

git send-email --smtp-server=$GOPATH/bin/sendgmail patch-test.diff
Answered By: Tim Potter
Categories: Answers Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.