1

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 [email protected] -setup

1. Ensure that you are logged in as [email protected] in your browser.

2. Open the following link and authorise sendgmail:
https://accounts.google.com/o/oauth2/auth?...

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?

5
  • Your information may be incomplete. From the link you referenced: If "Less secure app access" is turned off for your account, you can turn it back on. We recommend switching to more secure apps instead. I still use gmail as an smtp server. Google complains about it sometimes, but as long as you use it regularly, it seems to work for me
    – Seamus
    Commented Jun 9, 2022 at 2:00
  • 1
    Really it does not work for me: 5.7.8 Username and Password not accepted. Learn more at https://support.google.com/mail/?p=BadCredentials.
    – pevik
    Commented Jun 9, 2022 at 17:49
  • Ach! You're correct - they've disabled it completely. Bummer... spammers have killed email. You've no access unless you "affiliate" with a big tech company, and now it seems even that is compromised. I used to run my own SMTP server, but gave it up years ago b/c so much of my outgoing mail never reached its destination. Hope you find an answer!
    – Seamus
    Commented Jun 9, 2022 at 21:56
  • 1
    If you turn 2FA on, then you'll have the option to generate an app-specific password, which you can use instead of a password along with your regular username.
    – bk2204
    Commented Jun 12, 2022 at 21:00
  • @bk2204 Thanks, also noticed (unix.stackexchange.com/questions/172666/gmail-blocking-mutt/…), but I'd prefer to avoid 2FA.
    – pevik
    Commented Jun 13, 2022 at 16:19

1 Answer 1

2
+100

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 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 &scope):

http://localhost/?state=state&code=foobarauthcode&scope=https://mail.google.com/

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 protected] patch-test.diff
6
  • I'm not sure if I have "a valid workspace", that's the most difficult part. Yes, installing go it's ok, running commands in shell is ok, configuring git is ok. The problem is to understand workspace setup (i.e. understand google web UI setup).
    – pevik
    Commented Jun 10, 2022 at 10:52
  • I've updated the answer, let me know if you need further expansion
    – Tim Potter
    Commented Jun 10, 2022 at 11:14
  • Thx, I'll test it tonight. So they expect I run some go software instead of just printing toat code on their web page, lol. I should have looked to parameters myself, thanks!
    – pevik
    Commented Jun 13, 2022 at 16:26
  • I see Gmail API: API Enabled and enabled myself as user. I don't have an authorized domain. It fails when sending: Unable to initialize SMTP properly. Check config and use --smtp-debug. VALUES: server=~/go/bin/sendgmail encryption=tls hello=localhost.localdomain port=587 at /usr/lib/git-core/git-send-email line 1684 :(.
    – pevik
    Commented Jun 13, 2022 at 22:48
  • Could you please add more info about authorized domain? (link)
    – pevik
    Commented Jun 14, 2022 at 18:43

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .