UPDATE: I solved this by setting myorigin to $myhostname ("prime.example.com"). Now system mail goes to "[email protected]", which is what I wanted. My app explicitly says it wants to send from "[email protected]", and that works too. I'm not entirely sure this is the proper way of doing things, so I remain open to further suggestions.
I want locally generated mail currently sent via smtp to instead be delivered locally. Right now they go to user@domain instead of user@hostname. I'm using Postfix 2.11 on Ubuntu Server 14.04.
Domain: example.com
Hostname: prime.example.com
/etc/hosts:
127.0.1.1 prime.example.com prime
127.0.0.1 localhost
/etc/postfix/main.cf excerpt:
myhostname = prime.example.com
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
myorigin = /etc/mailname ("example.com")
mydestination = prime.example.com, localhost.example.com localhost
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = 127.0.0.1
inet_protocols = all
MX records for example.com point elsewhere; the server is used to send e-mail, not receive.
I can send email locally (showing from: [email protected]) from the command line by:
echo "This is the body of the email" | mail -s "This is the subject line" root
I can also send email via smtp for the domain (showing from: [email protected]) from cli by:
echo "This is the body of the email" | mail -s "This is the subject line" -a "From: [email protected]" <to-address>
However, when a simple cron job runs, mail is being sent via smtp to [email protected], not locally to [email protected] as I want.
I thought mydestination
was supposed to prevent sending mail non-locally, so either I'm mistaken or I have a configuration problem somewhere. Any tips would be much appreciated.