gmail sendgmail configuration for git send-email
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.
sendgmail requires certain configuration in Google Cloud, download JSON with configuration and rename to
~/.sendgmail.json and then run once:
$ GOPATH/bin/sendgmail -sender=USERNAME@gmail.com -setup 1. Ensure that you are logged in as USERNAME@gmail.com in your browser. 2. Open the following link and authorise sendgmail: https://accounts.google.com/o/oauth2/auth?... 3. Enter the authorisation code:
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?
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.
- Type: OAuth Client ID
- Application Type: Desktop App (others may work, just following linked guidance)
Install the sendgmail go package:
go install github.com/CyCoreSystems/gmail-oauth/sendgmail@latest
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
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 --email@example.com patch-test.diff