RHEL sends mail as myhost.localdomain but I don't want the localdomain suffix/FQDN

I have several machines that used to run Ubuntu 10.04. The OS were changed to RHEL7. After the change, programs like cron and mail send mail as [email protected] whereas on Ubuntu it was myuser@myhost. I prefer the Ubuntu way, without the localdomain suffix, and would like my RedHat installs to work the same way. How can I do this?

/etc/hosts looks like this:

127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
1.2.3.4 myhost.example.com myhost

hostname -f shows myhost.example.com; hostname shows myhost (all of which seems OK, and the same as on Ubuntu).


The program which modified the sender was postfix.

  1. By default crontab/mail will use username as email sender without domain parts. So the sender becomes myuser
  2. Because postfix sees sender doesn't domain name, by default postfix will append hostname as its domain. See parameter append_at_myorigin and myorigin in /etc/postfix/main.cf. The sender becomes myuser@myhost
  3. Because myhost isn't FQDN. So it will append localdomain in sender. See parameter append_dot_mydomain and mydomain in /etc/postfix/main.cf. The sender becomes [email protected]

Solution

  • Set parameter append_dot_mydomain in /etc/postfix/main.cf become no.
  • Restart postfix

I am not sure from where the crontab picks up the hostname part of the from email address, but one thing that you can do is to add a MAILFROM= line on the very top of the crontab so that it will send the email from the address mentioned in the MAILFROM= line.

[root@mercury01 ~]# crontab -l
[email protected]

*/10 * * * * sh /usr/local/src/disk-usage

[root@qa3app01 ~]#