| Linode Forum https://forum.linode.com/ |
|
| Postfix: alias one address to all users https://forum.linode.com/viewtopic.php?f=11&t=7944 |
Page 1 of 1 |
| Author: | Piki [ Sat Oct 22, 2011 5:05 pm ] |
| Post subject: | Postfix: alias one address to all users |
I want to be able to have an email alias in postfix that points one email address to all my users, including users I add in the future (e.g. team@mydomain.com -> olduser1, olduser2, olduser3, newuser). My setup uses a per-user maildir, and I have the required maildir in my system's skel (/etc/skel/mail/), so each user added is automatically able to send/receive emails, and I have all my old users aliased properly via /etc/aliases. 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 team@mydomain.com should go to every single user on my system (including new users)? |
|
| Author: | hoopycat [ Sat Oct 22, 2011 7:05 pm ] |
| Post subject: | |
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): Code: for i in `find /home/*/mail -maxdepth 0 | cut -d'/' -f3`; do You can then probably deliver to it with: Code: 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. |
|
| Author: | Azathoth [ Sat Oct 22, 2011 8:45 pm ] |
| Post subject: | |
Procmail? |
|
| Author: | Piki [ Sat Oct 22, 2011 9:50 pm ] |
| Post subject: | |
hoopycat wrote: 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 wrote: Code: for i in `find /home/*/mail -maxdepth 0 | cut -d'/' -f3`; do You can then probably deliver to it with: Code: 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 wrote: -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 wrote: Procmail?
Possible to do when Postfix already uses Procmail to handle maildir delivery? (postfix seems to default to mbox unless I explicitly set the mailbox_command to push email to procmail for maildir delivery, even though I have home_mailbox set to the correct directory name (e.g. "home_mailbox = mail/")) |
|
| Author: | Piki [ Sat Oct 22, 2011 10:50 pm ] |
| Post subject: | |
Twenty searches later and five pages in, Google finally reveals that the aliases file can accept a plain-text list of user as such: Code: 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: Code: awk -F: '$3 > 100 { print $1 }' /etc/passwd > /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). |
|
| Author: | Vance [ Sat Oct 22, 2011 11:20 pm ] |
| Post subject: | |
Don't make awk sad by ignoring its capabilities - it can do the job all by itself without any help from sed! Code: 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. |
|
| Author: | Piki [ Sat Oct 22, 2011 11:25 pm ] |
| Post subject: | |
Vance wrote: Don't make awk sad by ignoring its capabilities - it can do the job all by itself without any help from sed! Code: awk -F: '$3 > 100 && $1 != "sysuser1" && $1 != "sysuser2" [...] { print $1 }' /etc/passwd > /etc/mail/teamThanks for the tip, didn't realize awk could do that (I don't use it often). Of course, now sed will be sad Vance wrote: 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. |
|
| Author: | hoopycat [ Sun Oct 23, 2011 12:19 am ] |
| Post subject: | |
Ah hell, good call on the :include: ... it has been a long, long time since I've had to do this without SQL, Mailman, or Django ORM. That's exactly how you should do it. (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: Code: 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 |
|
| Author: | Piki [ Sun Oct 23, 2011 12:26 am ] |
| Post subject: | |
hoopycat wrote: '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 |
|
| Page 1 of 1 | All times are UTC-04:00 |
| Powered by phpBB® Forum Software © phpBB Group http://www.phpbb.com/ |
|