Gmail not automatically syncing Samsung A40 OneUi 1.1
Connected to wifi
After an email arrives to inbox, the phone (screen turned off) will not register this and no notification is given. After waking up it will sometimes sync but not always, after opening Gmail app it will usually sync but not always. Waiting for dozens of minutes and still nothing.

In such case, when I go to Account > (account) > syncing then Gmail syncing is enabled, but "last synced" can be e.g. 20+ minutes old.

Clicking to sync icon manually there or by pulling down in Gmail app it would sync successfully. I've read that the info about new mails is supposed to be pushed to the device so not sure why syncing is necessary actually, but it works like that...
2 Gmail accounts are bound to the device, but both have the same behavior

I tried (when account-related then was done for both accounts)
- Re-enabling syncing of Gmail
- Global auto sync is enabled
- Mobile data background usage is allowed (it's on wifi, but ... just to be sure)
- Wifi works correctly
- Checked battery settings - changed global to optimized mode (which is the most performance-focused and least battery optimization-focused mode available despite the name)
- Gmail is not set to be forced to sleep
- Gmail working in background is not disabled
- Checked memory-related settings, not seeing anything off
- Syncing is enabled within Gmail app itself > account settings.
- Notifications within Gmail app's own settings screen are enabled
- All notification options are enabled for Gmail app in the system screen for notification settings of the app
- No optimization 3rd party app etc. is running there
- Restart didn't help

Any idea how to fix this? Thank you
Had the same issue. I have also checked everything twice and this is how I have finally fixed it. I went in the Settings -> Apps -> gmail -> Storage -> Clear Data, then restarted my phone.