As a normal user I can send email, either from the commandline or from PHP. But when a cron job has error output, sending of that email fails (I have a MAILTOfirstname.lastname@example.org at the top of the crontab). The same happens for sending from the commandline as root (*).
I've tracked this down to: when the emails work the From and Return Path headers are set to email@example.com. That domain is the one set in /etc/mail/sendmail.mc, i.e. I have these three lines:
FEATURE(`allmasquerade') dnl MASQUERADE_DOMAIN(`valid.domain.com.')dnl MASQUERADE_AS(valid.domain.com)dnl
For the emails that fail, the From and Return Path headers are set to firstname.lastname@example.org. example2.com exists, but machinename has no DNS entry. Therefore the email gets refused with a 550. machinename.example2.com is the first entry in /etc/hosts for 127.0.0.1.
I suspect changing /etc/hosts with valid.domain.com might work but this is a production web server and I don't want to break anything else. It also feels like the wrong place to solve an email problem. So I'm hoping it is a sendmail or cron setting I need. (On another machine, ubuntu/postfix, I seem to have created /etc/postfix/sender_canonical to do this.)
OS: Centos 5.6
Mail Server: sendmail 8.13.8
*: but in that case the error correctly gets sent to email@example.com, as I have set the alias for root in /etc/aliases. This doesn't happen with the cron emails though; those bounce emails get put in my local unix mailbox.