Shell emailing from script

blimpyboy

New Member


Messages: 5

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.
 

ralphbsz

Daemon

Reaction score: 1,250
Messages: 1,999

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.
 
OP
OP
B

blimpyboy

New Member


Messages: 5

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.
 

_martin

Aspiring Daemon

Reaction score: 168
Messages: 811

What does /var/log/maillog say when you attempt to send an email ?
 
Top