[GH-ISSUE #190] Unable to setup gmail account using custom oauth2 #130

Closed
opened 2026-03-03 01:20:03 +03:00 by kerem · 9 comments
Owner

Originally created by @krackout on GitHub (Feb 9, 2026).
Original GitHub issue: https://github.com/d99kris/nmail/issues/190

Originally assigned to: @d99kris on GitHub.

Description:
Unable to setup gmail account using oauth2.

As in the nmail readme - gmail prerequisites, I enabled IMAP, setup my own OAuth 2.0 application with Google and configured ~/.config/nmail/auth.conf with my ID and secret. I started nmail --setup gmail-oauth2 but it fails (the app is not approved). I noticed that in the browser, opened as it should to enter username/password to approve the app, app name "nmail email client" is shown instead of the custom name I had given.

To be certain that my OAuth 2.0 application with Google is correctly setup, I setup claws-mail using oauth2, same gmail account; it worked flawlessly. The difference I could see was that when browser opened to enter username/password to approve the app, the app name was the custom one I entered while creating my own OAuth2 app in Google (apparently read from the entered ID in oauth2 settings). Claws-mail is also not approved by google, so it was a suitable candidate to simulate the behaviour.

How to reproduce it:
nmail --setup gmail-oauth2
After first run, when ~/.config/nmail dir is created, I made ~/.config/nmail/auth.conf with my ID and secret and retried nmail --setup gmail-oauth2. Same result. It seems to me that auth.conf file is ignored (or something is wrong on my setup), that's why nmail still uses its name, "nmail email client", apparently its ID also, instead of the one I set in auth.conf.

Environment:

  • Version: 5.10.3
  • OS / distro: Debian Linux 13 (trixie)
**auth.conf**
oauth2_client_id=MyID
oauth2_client_secret=MySecret

I also tried my ID and secret quoted, no difference.

**log.txt** (run using -ee parametre)
2026-02-09 10:38:39.546 | INFO  | nmail 5.10.3  (main.cpp:174)
2026-02-09 10:38:39.546 | INFO  | debian gnu/linux 13 (trixie) x86_64  (main.cpp:176)
2026-02-09 10:38:39.546 | INFO  | gcc 14.2.0 glibc 2.41  (main.cpp:178)
2026-02-09 10:38:39.546 | DEBUG | init /home/kr/.config/nmail/cache/  (cacheutil.cpp:54)
2026-02-09 10:38:39.547 | DEBUG | GenerateToken(gmail-oauth2)  (auth.cpp:95)
2026-02-09 10:38:39.547 | DEBUG | init /home/kr/.config/nmail/cache/auth/  (cacheutil.cpp:54)
Originally created by @krackout on GitHub (Feb 9, 2026). Original GitHub issue: https://github.com/d99kris/nmail/issues/190 Originally assigned to: @d99kris on GitHub. **Description**: Unable to setup gmail account using oauth2. As in the nmail readme - gmail prerequisites, I enabled IMAP, setup my own OAuth 2.0 application with Google and configured `~/.config/nmail/auth.conf` with my ID and secret. I started `nmail --setup gmail-oauth2` but it fails (the app is not approved). I noticed that in the browser, opened as it should to enter username/password to approve the app, app name "nmail email client" is shown instead of the custom name I had given. To be certain that my OAuth 2.0 application with Google is correctly setup, I setup [claws-mail](https://www.claws-mail.org/faq/index.php/Oauth2) using oauth2, same gmail account; it worked flawlessly. The difference I could see was that when browser opened to enter username/password to approve the app, the app name was the custom one I entered while creating my own OAuth2 app in Google (apparently read from the entered ID in oauth2 settings). Claws-mail is also not approved by google, so it was a suitable candidate to simulate the behaviour. **How to reproduce it**: `nmail --setup gmail-oauth2` After first run, when ~/.config/nmail dir is created, I made ~/.config/nmail/auth.conf with my ID and secret and retried `nmail --setup gmail-oauth2`. Same result. It seems to me that `auth.conf` file is ignored (or something is wrong on my setup), that's why nmail still uses its name, "nmail email client", apparently its ID also, instead of the one I set in auth.conf. **Environment**: - Version: 5.10.3 - OS / distro: Debian Linux 13 (trixie) ``` **auth.conf** oauth2_client_id=MyID oauth2_client_secret=MySecret ``` I also tried my ID and secret quoted, no difference. ``` **log.txt** (run using -ee parametre) 2026-02-09 10:38:39.546 | INFO | nmail 5.10.3 (main.cpp:174) 2026-02-09 10:38:39.546 | INFO | debian gnu/linux 13 (trixie) x86_64 (main.cpp:176) 2026-02-09 10:38:39.546 | INFO | gcc 14.2.0 glibc 2.41 (main.cpp:178) 2026-02-09 10:38:39.546 | DEBUG | init /home/kr/.config/nmail/cache/ (cacheutil.cpp:54) 2026-02-09 10:38:39.547 | DEBUG | GenerateToken(gmail-oauth2) (auth.cpp:95) 2026-02-09 10:38:39.547 | DEBUG | init /home/kr/.config/nmail/cache/auth/ (cacheutil.cpp:54) ```
kerem 2026-03-03 01:20:03 +03:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@d99kris commented on GitHub (Feb 9, 2026):

Hi @krackout - thanks for reporting a bug, I can reproduce the issue here as well. I'll take a look at fixing it, but I'm away for two weeks so it'll take a little while. Meanwhile, feel free to request an invite if you like to use the nmail OAuth2 project, until we get custom oauth2 client working.

<!-- gh-comment-id:3871534333 --> @d99kris commented on GitHub (Feb 9, 2026): Hi @krackout - thanks for reporting a bug, I can reproduce the issue here as well. I'll take a look at fixing it, but I'm away for two weeks so it'll take a little while. Meanwhile, feel free to [request an invite](https://github.com/d99kris/nmail#oauth-20-authentication) if you like to use the nmail OAuth2 project, until we get custom oauth2 client working.
Author
Owner

@krackout commented on GitHub (Feb 9, 2026):

Hi Kristofer!
The best email client, for free and open source (I have tried many, paid also). The least I can do is to wait :)

If it cannot be solved, I'll send a request, thank you.

Στις 2026-02-09 14:52 ο/η Kristofer Berggren @.***> έγραψε:

d99kris left a comment 1

Hi @.*** - thanks for reporting a bug, I can reproduce the issue
here as well. I'll take a look at fixing it, but I'm away for two weeks so
it'll take a little while. Meanwhile, feel free to [3]request an invite if
you like to use the nmail OAuth2 project, until we get custom oauth2 client
working.


Reply to this email directly, [4]view it on GitHub, or [5]unsubscribe.
You are receiving this because you were mentioned.Message ID:
@.***>

References

Visible links

  1. https://github.com/d99kris/nmail/issues/190#issuecomment-3871534333 2.
    https://github.com/krackout
  2. https://github.com/d99kris/nmail#oauth-20-authentication
  3. https://github.com/d99kris/nmail/issues/190#issuecomment-3871534333 5.
    https://github.com/notifications/unsubscribe-auth/AIWPMR24GJ3C23DAFYKZKX34LB
    7KDAVCNFSM6AAAAACUOUH662VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZTQNZRGUZTIM
    ZTGM
<!-- gh-comment-id:3873418202 --> @krackout commented on GitHub (Feb 9, 2026): Hi Kristofer! The best email client, for free and open source (I have tried many, paid also). The least I can do is to wait :) If it cannot be solved, I'll send a request, thank you. Στις 2026-02-09 14:52 ο/η Kristofer Berggren ***@***.***> έγραψε: > d99kris left a comment [1](d99kris/nmail#190) > > Hi ***@***.*** - thanks for reporting a bug, I can reproduce the issue > here as well. I'll take a look at fixing it, but I'm away for two weeks so > it'll take a little while. Meanwhile, feel free to [3]request an invite if > you like to use the nmail OAuth2 project, until we get custom oauth2 client > working. > > — > Reply to this email directly, [4]view it on GitHub, or [5]unsubscribe. > You are receiving this because you were mentioned.Message ID: > ***@***.***> > > References > > Visible links > 1. https://github.com/d99kris/nmail/issues/190#issuecomment-3871534333 2. > https://github.com/krackout > 3. https://github.com/d99kris/nmail#oauth-20-authentication > 4. https://github.com/d99kris/nmail/issues/190#issuecomment-3871534333 5. > https://github.com/notifications/unsubscribe-auth/AIWPMR24GJ3C23DAFYKZKX34LB > 7KDAVCNFSM6AAAAACUOUH662VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZTQNZRGUZTIM > ZTGM
Author
Owner

@d99kris commented on GitHub (Feb 22, 2026):

Hi again,
Thanks for the kind feedback :)

Custom oauth2 client support should be fixed in 97687c4 / v5.11.1.

For reference, I used the following steps to test:

Note: Using a non-default config dir (-d ~/.nmail-custom-oauth2) is not needed.

  1. Run nmail once to create config dir
nmail -d ~/.nmail-custom-oauth2
  1. Create / edit ~/.nmail-custom-oauth2/auth.conf and set id / secret:
oauth2_client_id=3652362............googleusercontent.com
oauth2_client_secret=GXSP..............Q0
  1. Run setup
nmail -d ~/.nmail-custom-oauth2 -s gmail-oauth2
  1. In the browser window opened:
  • Confirm your app name is shown on sign in page
  • Select account, click continue, click continue, tick checkbox "Read, compose, send, and permanently
    delete all your email from Gmail." and click continue.
  1. The browser should display "Authentication successful" and nmail should login.

Let me know if you encounter any issues!

<!-- gh-comment-id:3939958148 --> @d99kris commented on GitHub (Feb 22, 2026): Hi again, Thanks for the kind feedback :) Custom oauth2 client support should be fixed in 97687c4 / `v5.11.1`. For reference, I used the following steps to test: Note: Using a non-default config dir (`-d ~/.nmail-custom-oauth2`) is _not_ needed. 1. Run nmail once to create config dir ``` nmail -d ~/.nmail-custom-oauth2 ``` 2. Create / edit `~/.nmail-custom-oauth2/auth.conf` and set id / secret: ``` oauth2_client_id=3652362............googleusercontent.com oauth2_client_secret=GXSP..............Q0 ``` 3. Run setup ``` nmail -d ~/.nmail-custom-oauth2 -s gmail-oauth2 ``` 4. In the browser window opened: - Confirm your app name is shown on sign in page - Select account, click continue, click continue, tick checkbox "Read, compose, send, and permanently delete all your email from Gmail." and click continue. 5. The browser should display "Authentication successful" and nmail should login. Let me know if you encounter any issues!
Author
Owner

@krackout commented on GitHub (Feb 23, 2026):

I did the steps as instructed but I still haven't connected.

  • In the browser window, the proper custom name of my app is shown now.
  • When I select my account, I'm given a notice that the custom app will have access to my name, photo and e-mail address. No check boxes to select.
  • The browser displays "Authentication successful", but
  • I get this result from nmail -d ~/.nmail-custom-oauth2 -s gmail-oauth2 command:
token request failed <__main__.HttpResponse object at 0x7f521d40fcb0>
{'error': 'invalid_grant', 'error_description': 'Malformed auth code.'}
gmail-oauth2 setup failed, exiting.

Log:

2026-02-23 18:24:10.141 | INFO  | nmail 5.11.3  (main.cpp:174)
2026-02-23 18:24:10.141 | INFO  | debian gnu/linux 13 (trixie) x86_64  (main.cpp:176)
2026-02-23 18:24:10.142 | INFO  | gcc 14.2.0 glibc 2.41  (main.cpp:178)
2026-02-23 18:24:39.606 | WARN  | oauth2 generate failed (5): /usr/local/bin/oauth2nmail -g > /home/kr/.config/nmail/gp/temp/tmpfile.ABxmrK.txt 2>&1  (auth.cpp:345)

It seems that something is wrong from my side, but Claws Mail connected successfully. I changed secret, because I had already used it in Claws Mail. Still the same. I have no knowledge of oauth2, should I delete the client in Google auth platform, because it was already used when I tested Claws? I'm currently doing this, but it takes some time.

I'm not reopening the issue, I need to test further. I mentioned the results just in case you see something obvious that I miss.

<!-- gh-comment-id:3946078709 --> @krackout commented on GitHub (Feb 23, 2026): I did the steps as instructed but I still haven't connected. - In the browser window, the proper custom name of my app is shown now. - When I select my account, I'm given a notice that the custom app will have access to my name, photo and e-mail address. No check boxes to select. - The browser displays "Authentication successful", but - I get this result from `nmail -d ~/.nmail-custom-oauth2 -s gmail-oauth2` command: ``` token request failed <__main__.HttpResponse object at 0x7f521d40fcb0> {'error': 'invalid_grant', 'error_description': 'Malformed auth code.'} gmail-oauth2 setup failed, exiting. ``` Log: ``` 2026-02-23 18:24:10.141 | INFO | nmail 5.11.3 (main.cpp:174) 2026-02-23 18:24:10.141 | INFO | debian gnu/linux 13 (trixie) x86_64 (main.cpp:176) 2026-02-23 18:24:10.142 | INFO | gcc 14.2.0 glibc 2.41 (main.cpp:178) 2026-02-23 18:24:39.606 | WARN | oauth2 generate failed (5): /usr/local/bin/oauth2nmail -g > /home/kr/.config/nmail/gp/temp/tmpfile.ABxmrK.txt 2>&1 (auth.cpp:345) ``` It seems that something is wrong from my side, but Claws Mail connected successfully. I changed secret, because I had already used it in Claws Mail. Still the same. I have no knowledge of oauth2, should I delete the client in Google auth platform, because it was already used when I tested Claws? I'm currently doing this, but it takes some time. I'm not reopening the issue, I need to test further. I mentioned the results just in case you see something obvious that I miss.
Author
Owner

@d99kris commented on GitHub (Feb 23, 2026):

Hi, just a quick reply on this:

should I delete the client in Google auth platform, because it was already used when I tested Claws?

No, it's not needed. One can use same client in Google for many apps.

If the browser reaches "Authentication successful" I suspect it's a bug in nmail. I'll see if I can try on Debian. But meanwhile can I check what python version you have? python --version

<!-- gh-comment-id:3947962414 --> @d99kris commented on GitHub (Feb 23, 2026): Hi, just a quick reply on this: > should I delete the client in Google auth platform, because it was already used when I tested Claws? No, it's not needed. One can use same client in Google for many apps. If the browser reaches "Authentication successful" I suspect it's a bug in nmail. I'll see if I can try on Debian. But meanwhile can I check what python version you have? `python --version`
Author
Owner

@krackout commented on GitHub (Feb 24, 2026):

Python 3.13.5, the default version supplied by Debian 13 (Trixie)

On 2026-02-24 01:41 Kristofer Berggren @.***> wrote:

d99kris left a comment 1

Hi, just a quick reply on this:

should I delete the client in Google auth platform, because it was already
used when I tested Claws?

No, it's not needed. One can use same client in Google for many apps.

If the browser reaches "Authentication successful" I suspect it's a bug in
nmail. I'll see if I can try on Debian. But meanwhile can I check what
python version you have? python --version

<!-- gh-comment-id:3949558162 --> @krackout commented on GitHub (Feb 24, 2026): Python 3.13.5, the default version supplied by Debian 13 (Trixie) On 2026-02-24 01:41 Kristofer Berggren ***@***.***> wrote: > d99kris left a comment [1](d99kris/nmail#190) > > Hi, just a quick reply on this: > >> should I delete the client in Google auth platform, because it was already >> used when I tested Claws? > > No, it's not needed. One can use same client in Google for many apps. > > If the browser reaches "Authentication successful" I suspect it's a bug in > nmail. I'll see if I can try on Debian. But meanwhile can I check what > python version you have? python --version
Author
Owner

@d99kris commented on GitHub (Feb 24, 2026):

Thanks 👍 I don't have 13 (Trixie) at the moment, but I tested 12 without issues using custom oauth2 just now. So at least it's not a general Linux or general Debian issue.

Maybe it's some locale incompatibility in the nmail python script. What's your output from locale?

If no other luck, I could invite you to my custom oauth2 app, and then let you capture -ee (extra verbose logging), and share the log privately with me on d99kris at gmail dot com (I believe the log will contain secrets)..

<!-- gh-comment-id:3952355156 --> @d99kris commented on GitHub (Feb 24, 2026): Thanks 👍 I don't have 13 (Trixie) at the moment, but I tested 12 without issues using custom oauth2 just now. So at least it's not a general Linux or general Debian issue. Maybe it's some locale incompatibility in the nmail python script. What's your output from `locale`? If no other luck, I could invite you to my custom oauth2 app, and then let you capture `-ee` (extra verbose logging), and share the log privately with me on `d99kris at gmail dot com` (I believe the log will contain secrets)..
Author
Owner

@d99kris commented on GitHub (Feb 28, 2026):

I tested now on a fresh Debian 13 (Trixie) x86_64 VM and it's working fine with custom oauth2 app with gmail.

Will however reopen this issue so I don't lose track of it, until it's resolved.

<!-- gh-comment-id:3977247504 --> @d99kris commented on GitHub (Feb 28, 2026): I tested now on a fresh Debian 13 (Trixie) x86_64 VM and it's working fine with custom oauth2 app with gmail. Will however reopen this issue so I don't lose track of it, until it's resolved.
Author
Owner

@krackout commented on GitHub (Mar 2, 2026):

You were right! It was the locale settings. Mine are LC_ALL=el_GR.UTF-8. I temporarily switched to LC_ALL=C and LANG=C and setup completed smoothly. Setting locale to C is a bit hard core, but I wanted to be on the safe side. Now I run nmail with LC_ALL=el_GR.UTF-8 (to be able to view unicode characters as with my other instances of nmail) and it works fine. Switching locale was needed only during setup.

Time to regain my gmail mailbox!

<!-- gh-comment-id:3986310545 --> @krackout commented on GitHub (Mar 2, 2026): You were right! It was the locale settings. Mine are `LC_ALL=el_GR.UTF-8`. I temporarily switched to `LC_ALL=C` and `LANG=C` and setup completed smoothly. Setting locale to C is a bit hard core, but I wanted to be on the safe side. Now I run nmail with `LC_ALL=el_GR.UTF-8` (to be able to view unicode characters as with my other instances of nmail) and it works fine. Switching locale was needed only during setup. Time to regain my gmail mailbox!
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/nmail#130
No description provided.