0

I have a mail server (postfix 2.9.6) up and running with 15-20 users, only for internal usage with one single domain, let's call it xyz.mail.lan

Users are:

    user1@xyz.mail.lan
    user2@xyz.mail.lan
    user3@xyz.mail.lan
    …
    user5@xyz.mail.lan

No external relay, or incoming mails from internet side is necessary. It works fine right now.

My goal is to limit the users in sending mails to each other.

For example:

  • user1 is allowed to send mails only to: user2, user3, user4, user5
  • user2 is allowed to send mails only to: user1, user3
  • user3 is allowed to send mails only to: user1, user5
  • user5 is allowed to send mails only to: user1, user4

I will not have more than 20 users, so I don't mind if my hands has to be dirty with setting up ugly rules for each user.

  • You might be able to use procmail for this, but I'm not sure where it would fit in as I don't have the full picture. Are you using something like dovecot for mailbox access? – Gene Oct 2 '14 at 8:52
2

If you want to quick and dirty solution (because of few user) and without external script/daemon (just using postfix and its maps), take a look in Postfix Restriction Classes. In that page, you should see examples how that feature works. In short, every class will have own set of restriction just like you want.

For your case, first you will add this checks table in smtpd_*_restriction, for example smtpd_recipient_restriction

smtpd_recipient_restriction = 
           ... other restriction....
           check_sender_access hash:/etc/postfix/sender_rules

smtpd_restriction_classes = user1_rule, user2_rule, user3_rule,...

user1_rule = check_recipient_access hash:/etc/postfix/rules/user1
user2_rule = check_recipient_access hash:/etc/postfix/rules/user2
user3_rule = check_recipient_access hash:/etc/postfix/rules/user3
so on...

Content of /etc/postfix/sender_rules

user1     user1_rule
user2     user2_rule
user3     user3_rule
... others ...

The last is the content of /etc/postfix/rules/userX (where X is 1... number of users)

/etc/postfix/rules/user1

user2    OK
user3    OK
user4    OK
user5    OK

/etc/postfix/rules/user2

user1    OK
user3    OK

And the others...

  • Thanks for your input. I followed your advice, but no luck. I successfully generated the db files with postmap command, no errors with your config in syslog but the rules are simply not applied, mailes goes through against them. I think my problem is the "smtpd_recipient_restriction" line, I can't find a "sufficient-to-set" configuration that plays with your "check_sender_access hash:/etc/postfix/sender_rules" rule. – Paul Oct 3 '14 at 10:13
  • Disregard my previous message. I had to set full names like user1@xyz.mail.lan instead of user1 in /etc/postfix/sender_rules and in the /etc/postfix/rules/userX files Thank You. – Paul Oct 3 '14 at 10:18
1

Since your use case is very special and standard Postfix lookup methods do not work for you, I would consider using Postfix content inspection.

Usually it is used for anti-spam/virus filtering, but since you can hook up your own Perl/whatever scripts to it, you can create a small script with the language you like and let it answer to Postfix if the mail should be passed or not.

In pseudo-code, something like

if ($mailfrom == "user2" && ($rcptto == $user3 || $rcptto == $user5)) {
    yes_pass_the_mail();
}

should do. Take a look at Postfix documentation about filtering.

  • Thank You for pointing me to this direction. It is a half solution. I succeeded to create the filtering stuff depending on the header content, but there is a backdoor in this solution: BCC recipients. BCC addresses are not listed in headers. – Paul Oct 3 '14 at 9:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.