Is there a way to change the outbound email for root, i.e instead of root@localhost.localdomain
to root@apps.mydomain.com
?
I am using Postfix.
Modify the aliases file to your taste. It will be in /etc or /etc/mail or /etc/postfix or any other directory depending on your MTA. You may also need to rebuild alias db or reload your MTA (see the MTA documentation).
Situation: I renamed the Digital Ocean Droplet (the old domain was gone), however, the root mail was still sending mails with the old domain (when executing bash scripts). The old email was visible in the email header:
envelope-from
Return-path:
From: root@old.domain.com (root)
Using hostname=newdomain.com
then restarting the server did not help.
Likewise this did not help:
sudo postconf -e 'myhostname = newdomain.com'
sudo postconf -e 'smtp_helo_name = newdomain.com'
sudo service postfix restart
Then I looked into /etc/postfix/main.cf
which reveals one important line:
smtpd_banner = $myhostname ESMTP $mail_name (Ubuntu)
Finally, I could pinpoint the problem down to this file:
/etc/mailname
which was still having the old entry.
So I edited the file and set the new filename.
Afterwards in SSH I executed:
newaliases
(not sure if needed)sudo service postfix restart
And voila, the mail sent is from the new email address.
I have found the solution its smtp_generic_maps (default: empty)
Optional lookup tables that perform address rewriting in the SMTP client, typically to transform a locally valid address into a globally valid address when sending mail across the Internet. This is needed when the local machine does not have its own Internet domain name, but uses something like localdomain.local instead.