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.


edit-1:
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?

I resolved this issue by using Chromium instead of Firefox. I don’t know what the cause was, but it was probably a DNS setting, add-on, or cookie restriction I had set in Firefox that I didn’t have in Chromium.

Regardless, for anyone having this issue I would suggest using a different browser set to default settings.

Same issue:

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

When using Gmail/G Suite option. Mine is also a UCSD email like another user posted here. I tried both chromium and firefox to no avail.

Mailspring version 1.13.2
The browser successfully auths and shows me the “finished” screen but them Mailspring shows the error above.

I love Mailspring for my personal email and I just want to use it for work.

I am not using a VPN but am on the campus network. Does not work on home network either. Never tried using a vpn.

I have IMAP enabled as per https://www.reddit.com/r/UCSD/comments/jb9cal/using_3rd_party_email_clients/

Looking at:

They offer the solution of using an App Password, and when I choose IMAP/SMTP and use the app password it now tells me that:

Gmail IMAP is not enabled. Visit Gmail settings to turn it on. (IMAP)
Log:

----------IMAP----------
connect <mailcore::IMAPSession:0xffffffffffff>
* OK Gimap ready for requests from xxx.xxx.xxx.xxx
ssl connect imap.gmail.com 993 2
1 CAPABILITY
* CAPABILITY IMAP4rev1 UNSELECT IDLE NAMESPACE QUOTA ID XLIST CHILDREN X-GM-EXT-1 XYZZY SASL-IR AUTH=XOAUTH2 AUTH=PLAIN AUTH=PLAIN-CLIENTTOKEN AUTH=OAUTHBEARER
1 OK Thats all she wrote!
connect ok
login
2 LOGIN "jakrause@ucsd.edu" "*********"
2 NO [ALERT] IMAP access is disabled for this mail client for your domain. Please contact your domain administrator for questions about this feature. (Failure)

(I edited some values)

So, this leaves me thinking that it is restricted somehow from UCSD IT, and that one would probably have to reach out to them to see why.

How to solve issue?