I see a lot of questions about this, and I went through some headaches setting this up myself and the docs for osTicket are abysmal, so figured I'd write this up.
Configure in osTcket (the easy part):
Under Admin -> Emails ->Emails -> Sending email via SMTP
For most people, enter either
ssl://smtp.gmail.com with port 465
tls://smtp.gmail.com with port 587.
If you have a google apps/G-Suite account, this might change, see below.
Select "Authentication Required". Leave Header Spoofing unchecked.
Make sure your username is your full email and password are set correctly in the Email Login Information
If you test at this point and it doesn't work, continue reading.
Depending on your system, you may have an error_log file in the scp directory that may give you some more information as to why it's not working.
Check your Firewall
Connection Refused errors are most likely caused by your firewall.
If you are running csf, it defaults to block outgoing SMTP connections. You can either turn off SMTP_BLOCK (not recommended) or add the user osTicket is running under to SMTP_ALLOWUSER. Also make sure the port you are using (465 or 587) is in SMTP_PORTS.
If you are running some other firewall, make sure it is allowing outgoing connections on 465 or 587.
Not related to SMTP, but make sure you enabled IMAP or POP3 from Settings -> Forwarding and POP/IMAP
You may need to "allow less secure apps". From gmail, click your avatar at the top right of the page and click "My Account". In the left menu, under Sign-In & Security, click "Connected Apps and Sites". Scroll down to "Allow less secure apps" and turn it on and retest.
It is recommended to not leave this on unless necessary.
Check your G-Suite policies
G-Suite allows you to use their SMTP Relay service. This service allows you to open up SMTP under certain conditions. To use this service, you must configure it under Apps -> G-Suite > Gmail > Advanced Settings -> General Settings -> Routing
Add an SMTP relay service with the appropriate settings.
Make sure you change your osTicket configuration to use smtp-relay.gmail.com as the SMTP server.
Hope this helps