Sending email from my server

Solution 1:

What MTA are you using locally? mail just gives you the ability to form a mail message, but you still need and MTA to do the actual delivery? By default, most distributions come with sendmail. You'll likely need to install another MTA or configure the current one to support outside delivery.

Solution 2:

Because mailx expects a full SMTP infrastructure, which is not configured by default. What kind of SMTP server, if any, do you have installed (i.e. postfix, exim, sendmail, qmail)?

Solution 3:

# fgrep remote /var/log/exim4/mainlog.1 | sed -E 's#([ <])[^ <]+@[^ >]+([ >])#\1a@b\2#g' | head -1
2019-01-08 00:47:00 1ggebk-00055M-St ** a@b <a@b> R=nonlocal: Mailing to remote domains not supported

It would appear that Debian may come with an exim4 that's set to not work correctly on an internet-connected machine where the outgoing smtp ports aren't blocked.

As pointed out in various comments, to make it work correctly, one has to run dpkg-reconfigure exim4-config, and within the wizard, select the first internet option. Note that in subsequent dialogue boxes within the wizard, the defaults are still set to only listen on localhost IPv4/IPv6 addresses, so, it appears that, if you leave the other defaults alone, you're still leaving the incoming SMTP port alone.

To verify the wizard worked correctly, you can check the Debian-specific /etc/exim4/update-exim4.conf.conf (yes, it's a double .conf.conf, that's not a typo), which plays a part in this fiasco. Here's the relevant parts after running dpkg-reconfigure exim4-config and only changing the first option within the wizard, which enables sending mail, but keeps the SMTP port open only to the machine itself (a default option if you just click-through in the reconfig after the first option):

dc_local_interfaces=' ; ::1'

Another solution would be to install DragonFly Mail Agent in jessie and up — — which is a simple implementation of a MTA, implementing all the good UNIX mail things except for incoming SMTP, so, you don't have to worry about misconfiguration or external vulnerabilities.