Shell emailing from script

I have a script which runs on my FreeBSD 10.3-STABLE box via cron every evening at 10pm. It carries out an rsync of my files and emails me the result. For years it's been running perfectly... until recently! The line in the script looks something like:

echo "backup completed OK" | /usr/bin/mail -s "Backup result" me@mycompany.co.uk

I'm in the UK and have Virgin fibre broadband. I suspect it's related to Virgin blocking something that they used to allow, but I'm not sure what. Perhaps Virgin have stopped allowing relay of email and I now need to authenticate, but I don't see any support for that in the /usr/bin/mail man page.

If anyone can shed any light, or offer a simple solution, I'd be mighty grateful.
 
Most ISP's block outgoing port 25 for private subscription lines. In order to reliably achieve your goals, you would need to employ a mail relay server which got a non-blocked connection to the internet. You would send you mails on the submission ports 587 or 465 (tls) to the relay, which would then distribute it to receivers. This could be a gmail.com account for example.

I could neither find a setting in mail(1). Some times ago I wrote such a command line tool SMTPSend for sending out mails to a mail relay, see this thread:
 
Let's split your debugging into two levels. Why? Because mail works at two levels. First level is the MUA or Mail User Agent. That's a program that a human from the command line or from the GUI uses, to send and view mail. The mail() program you are using in your cron job script above is an MUA. The second level is the MTA or Mail Transport Agent. This is a (set of) daemons that run and that move mail back and forth. The mail() MUA communicates with the MTA.

First level debugging: Is the mail command in the line above working at all? Try this: Make a second copy of that line, and fix it like this:
# echo "backup completed OK" at `date` >> /tmp/my_mail_debug.log
This will show you whether your script even got there. If that works, then try sending e-mail to a local user (which doesn't have to go to the network and back), and see that it arrives. If this all works, proceed to the second level:

Configuring things like relaying, authentication, blocking, and all that is not done in the mail() mail program at all. Instead, there is a whole slew of different MUAs you can use. The default used to be sendmail(), and configuring sendmail can be made arbitrarily complex, there are several whole books about it. There are also other MUAs that people commonly use. Figure out which one you have installed, figure out whether it is the optimal one for your use case, and then configure it. There is a whole chapter in the handbook about it.

Another obnoxious remark: Your FreeBSD version is pretty obsolete. The best path might be to just update to a current version. I think newer MTAs and newer releases have more easy support for modern e-mail authentication, as obsigna explained.
 
Ralphbsz & obsigna, thanks for taking the time to consider & respond to my question, it is much appreciated. I'm not in the office today, but will debug as suggested tomorrow.
 
Back
Top