The problem with Mail.app on older Macs/OS's is that -- as ISP's and email providers have increased/revised their security protocols -- Mail.app seems to have problems with authentication with
some (not "all") email servers.
I don't believe this can be fixed "at the OS level". Apple isn't issuing updates for older versions of Mail.app. To get a newer version of Mail, you need a newer version of the OS.
The problem CAN be "worked around", in some cases.
My experience is limited to my own usage.
On my not-really-that-old 2018 Mini (running 10.14 Mojave), I started running into trouble trying to connect to ISP/email that is now hosted on Yahoo's email server system.
Trying to connect through Apple's "Internet Accounts" preference pane would end up in failed attempts -- the process seemed unable to complete.
Yahoo provides "a way around" this. You have to create something called an "application specific password" (generated by Yahoo) which you THEN enter into the email setup, seems to work around the security problems.
See this page for more:
If you use a 3rd-party email app to access your Yahoo Mail account, you may need a special code to give that app permission to access your Yahoo account. Learn how to create and delete app passwords.
help.yahoo.com
That got it working again for me.
Hmmmm...
Something else you should try if Apple Mail won't connect:
Open a web browser and see if you can connect to the provider's email that way.
I dislike web-based email, but if Mail.app is having problems, web/mail usually works.
Last thought:
You mentioned GMail.
I have no experience with them, but do recall reading numerous posts from other Mac users who have GMail -- and "have problems" as well.
But can't help with GMail...