Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have setup up a basic email server using PostFix with Dovecot/IMAP. But i face some issue with the blacklist setup.

below is my postfix main.cf

smtpd_recipient_restrictions = check_sender_access mysql:/etc/postfix/blacklist.cf reject_unauth_destination

blacklist.cf

user = mailuser
password = mailuser2011
hosts = 127.0.0.1
dbname = mailserver
query = SELECT 'REJECT' FROM blacklist WHERE email='%s' AND id=( SELECT id FROM virtual_users WHERE email='%u')

My SQL table have 2 columns for the blacklist. Namely the id and the email where id is the individual user and email is the blacklisted address.

What I want to do is to retrieve the address match from the database with reference to the recipient in the mail. If I hard code the email value to something existing in the database it will be able to reject mails from the blocked user.

However, if I uses the %u(which I assume it refers to the recipient), it fails to block at all.

share|improve this question

1 Answer 1

Lookup tables in Postfix are Key-Value-Lookups. That means you have a key and get a value after lookup. In your case (check_sender_access) the key is the sender; and only the sender. So your requirement of having two keys (sender and recipient) can not be done with Postfix.

The only way to solve that is by Policy Delegation, where you have multiple keys (sender, recipient, IP, hostname, helo, ...) to do your lookup.

But on the other hand it is a very bad idea to rely on the sender address, as this is the easiest thing to forge.

share|improve this answer
    
Thanks, I will look up on the Policy Delegation. I know it's a bad idea that's but currently just trying to work with the address only. Finally someone answered me :) Thanks for the help. –  Harris Nov 17 '11 at 2:35
    
Hi there, I tried working my way around with the policy delegation. Somehow I don't really get it. Guess it's because I'm new to Perl. Is there any samples that I can look at other than this? I'm having the error of attributes. –  Harris Nov 18 '11 at 17:31
    
This is not part of this question. You can use any programming language you are familiar with and which supports either Unix sockets or TCP/IP sockets. I did an implementation with Java without problems. –  mailq Nov 18 '11 at 22:03

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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