Postfix aliases not working for root?
While working on a new mail server this morning, I found that root was not receiving mail, so I needed a quick fix.Platform issues might be relevant for some admins, so let's find out how the server is configured to run Postfix...
Now that I have those particulars, I need to query the aliases database. But, how do you find that out? Let's look further...
Perfect. Let's move on to finding who receives root mail.
Wha??? No results? That an easy enough fix. Just fire up your favorite editor for /etc/aliases to add an entry for root.
Of course, don't forget that you@domain.com should be changed to suit your needs. But, we're not done! At this point, Postfix is not aware of our new alias settings, as it reads /etc/aliases.db, not /etc/aliases, so let's fix this. Some of the documentation I came across referred to using postmap to rebuild aliases.db, but I found that I ran into the 'record is in "key: value" format; is this an alias file?' warning. Well, I probably wasn't doing something right, so instead I tried an alternative:
I then check my work...
This time, I got the expected results: you@domain.com. Nice. So I watched the mail logs as I sent a test mail message:
For me, it worked. Yay!If your message could not be delivered, make sure you read the mail logs carefully for specific errors. Your server configuration might need to be tuned depending on your needs and the error generated, but that's for another post.Cheers.
sudo postconf -d | grep ^mail_version
mail_version = 2.3.8
cat /etc/issue
Debian GNU/Linux 4.0
Now that I have those particulars, I need to query the aliases database. But, how do you find that out? Let's look further...
sudo postconf -n | grep ^alias
alias_database = hash:/etc/aliases
alias_maps = hash:/etc/aliases
Perfect. Let's move on to finding who receives root mail.
postmap -q root hash:/etc/aliases
Wha??? No results? That an easy enough fix. Just fire up your favorite editor for /etc/aliases to add an entry for root.
root: you@domain.com
mailer-daemon: postmaster
postmaster: root
Of course, don't forget that you@domain.com should be changed to suit your needs. But, we're not done! At this point, Postfix is not aware of our new alias settings, as it reads /etc/aliases.db, not /etc/aliases, so let's fix this. Some of the documentation I came across referred to using postmap to rebuild aliases.db, but I found that I ran into the 'record is in "key: value" format; is this an alias file?' warning. Well, I probably wasn't doing something right, so instead I tried an alternative:
sudo newaliases
sudo postfix reload
I then check my work...
sudo postmap -q root /etc/aliases
This time, I got the expected results: you@domain.com. Nice. So I watched the mail logs as I sent a test mail message:
sudo tail -f /var/log/mail.log
For me, it worked. Yay!If your message could not be delivered, make sure you read the mail logs carefully for specific errors. Your server configuration might need to be tuned depending on your needs and the error generated, but that's for another post.Cheers.