Postfix: alias one address to all users
The problem is that it would be a pain having to add additional users to /etc/aliases in the future, postalias them, then restart postfix. This seems to be the route that every guide on Google wants me to take (or add them via webmin, which I don't use). Is it possible to tell postfix that any email sent to
8 Replies
for i in `find /home/*/mail -maxdepth 0 | cut -d'/' -f3`; do
/usr/sbin/sendmail -bm -f "mailer-daemon@`hostname -f`" "$i"
done
You can then probably deliver to it with:
blah |/path/to/that/file
in your /etc/aliases or whereever. A very half-baked solution so far (and untested), but the overall goal is to make it automatic.
@hoopycat:
Hmmm… something like this would probably do it, assuming users' mail is stored in /home/blah/Maildir and you want to only send to users with mailboxes (vs. every user in /etc/passwd):
Every user gets a maildir by default, hence the skel
@hoopycat:
for i in `find /home/*/mail -maxdepth 0 | cut -d'/' -f3`; do /usr/sbin/sendmail -bm -f "mailer-daemon@`hostname -f`" "$i" done
You can then probably deliver to it with:
blah |/path/to/that/file
in your /etc/aliases or whereever. A very half-baked solution so far (and untested), but the overall goal is to make it automatic.
I'm looking at the man page for postfix's sendmail. The '-f' option has me confused. It sets the sender envelope and is where errors are sent to. From my understanding, it replaces the sender information and tells postfix where to send errors?
@man sendmail:
-f sender
Set the envelope sender address. This is the address where delivery problems are sent to. With Postfix versions before 2.1, the Errors-To: message header overrides the error return address.
I also don't understand the second code block. I'm guessing the for loop will build a list of users with maildirs then produce a file containing those users, then I'd need to use that file to copy the email being sent to my global email address (e.g.team@mydomain.com )?
@Azathoth:
Procmail?
Possible to do when Postfix already uses Procmail to handle maildir delivery? (postfix seems to default to mbox unless I explicitly set the mailboxcommand to push email to procmail for maildir delivery, even though I have homemailbox set to the correct directory name (e.g. "home_mailbox = mail/"))
team: :include:/path/to/list
Going on this, I used awk to grab a list of users from /etc/passwd, then used sed to remove system users:
awk -F: '$3 > 100 { print $1 }' /etc/passwd > /etc/mail/allusers
sed -e '/sysuser1/d' -e '/sysuser2/d' [...] /etc/mail/allusers > /etc/mail/team
rm -f /etc/mail/allusers
I then adjusted the :include: example to include my list in /etc/aliases. Neither postalias nor newaliases complained, so I restarted postfix. My test email to my team email seems to have come through to me without problem, have to wait for my other users to wake up to see if it worked for them too. Provided it worked for them too, I can create a script to handle generating the team list for me and add it to cron (which shouldn't be a problem since I shouldn't need to install any software that'll add a system user in the foreseeable future).
awk -F: '$3 > 100 && $1 != "sysuser1" && $1 != "sysuser2" [...] { print $1 }' /etc/passwd > /etc/mail/team
I don't know if it's strictly necessary, but I'd suggest running newaliases any time you change the contents of the include file.
@Vance:
Don't make awk sad by ignoring its capabilities - it can do the job all by itself without any help from sed!
awk -F: '$3 > 100 && $1 != "sysuser1" && $1 != "sysuser2" [...] { print $1 }' /etc/passwd > /etc/mail/team
Thanks for the tip, didn't realize awk could do that (I don't use it often). Of course, now sed will be sad
@Vance:
I don't know if it's strictly necessary, but I'd suggest running newaliases any time you change the contents of the include file.
I'd say it'd be safe to do so, if I understand correctly from Google, newaliases works with what's already there, so anything added wouldn't take effect until after newaliases was run again, and anything removed would remain until the next newaliases.
(I was re-using a hunk of code that I'm using for SPF-friendly forwarding, since that was on the front of my mind, but don't do what I suggested. But you aren't anyway.)
Rather than notching out hardcoded values from /etc/passwd, the find trick might still do the magic:
find /home/*/mail -maxdepth 0 | cut -d'/' -f3 > /etc/mail/team
(assuming users are in /home and have their maildirs in /home/username/mail)
'course, worst thing that would happen with the /etc/passwd parsing is e-mailing new daemons all the time, so if it works, run with it
@hoopycat:
'course, worst thing that would happen with the /etc/passwd parsing is e-mailing new daemons all the time, so if it works, run with it
:-)
My daemons are lonely, they only ever see me, so they enjoy eavesdropping on email that shouldn't go to them