mail and derivatives (and almost any other Unix MUA) use the traditional
sendmail interface -
/usr/bin/sendmail, provided by almost all MTAs (postfix, exim, sendmail, courier). This is the traditional Unix way.
Once a message is submitted through
sendmail, your MTA handles message transmission. Depending on configuration, it may either connect directly to the destination MTA (if on a server), or relay mail through another host (also called a smarthost) - the latter is more common on personal computers, where relaying through your Gmail or ISP/work email account is essential.
(Some MTAs such as
nullmailer are built specifically for home users and always use a relayhost. These don't support receiving mail and are a lot lighter on resources.)
mailx → /usr/bin/sendmail → local MTA → recipient MTA → recipient inbox
mailx → /usr/bin/sendmail → local MTA → Gmail or ISP/work servers → recipient MTA → recipient inbox
Other programs (mostly the user-friendly graphical clients such as Thunderbird or Outlook) connect directly to a relay SMTP server (again, usually Gmail or ISP/work SMTP server), which transmits the message further.
SMTP support is present in
heirloom-mailx, but not in the traditional
app → Gmail or ISP/work servers → recipient MTA → recipient inbox
The third method - directly to recipient's server - is almost never used, and no MUA supports it. On personal computers, using it would cause your message to get rejected (a lot of spam is sent from infected home user IP addresses).