Cannot connect to Gmail from behind VPN

When behind some VPNs, attempting to connect to a Google account via Mailspring fails:

Connection Error - Unable to connect to the server / port you provided. (SMTP)

This appears to occur when Mailspring is behind a VPN.

For anybody who have spend hours fixing this issue

It seems to me that it is caused by mailsync traffic does not work properly with VPN on OS level.
I use surge (MacOS app) as my proxy client, I turned on enhanced mode (emulates a network interface instead of letting OS redirect the traffic) and mailspring just works.

As a probable suspicion, mailsync may not use the OS networking API properly. Possibly for compatibility or features.

OAuth use localhost as callback, and that is actually a more probable cause of problem

problem is not restricted to VPN, I’m having the same issue through a standard wifi connection.

Mailspring works great with my personal Gmail account and some of my .edu accounts (Google Workspace), but can’t get it to work with my UCSD one. I guess it has something to do with how the organization does SSO? Is there any log I can share to help debug this?