Send mail as hostname@example.com instead of root@example.com

emaileximpostfix

I'm trying to have emails sent as hostname@example.com. Hostname being the name of the machine. This way I know which machines are sending me alerts.

Running postfix on Debian 8. I created a generic file and listed

root@example.com    hostname@example.com

Ran postmap generic and restarted postfix after modifying the main.cf to reference the generic file.

When I send mail as root, it still arrives as root@example.com on the postfix server.

Any ideas what I'm doing wrong?

On a non-postfix machine, just running exim4, emails are sent as hostname@example.com but with the root in the from field (name). How can I remove the name? Do I just remove the name root from /etc/passwd ?

Best Answer

The only thing you have to do is to add appropriate line to the begin rewrite section of exim's config:

begin rewrite
  . . . . . .
  root@example.com    hostname@example.com    Ffrsw

Here flags Ffrs defines what headers will be rewrited:

  • F = ENVELOPE FROM
  • f = FROM
  • r = RETURN-PATH
  • s = SENDER
  • w = Complete rewrite, i.e. <Root> root@example.com become hostname@example.com