How can I block outgoing mail for a specific user (user@example.com) in Postfix to all but a specific list of domains (e.g. @example.com, @dot1q.com)?

I found a solution to block mail to a specific domain:

Edit the main.cf file (the default location is in /etc/postfix) and add transport_maps = hash:/etc/postfix/transport to the file. Create a file named /etc/postfix/transport, if it doesn’t exist. Add the following at the end of the transport file: example.com : dot1q.com : * discard:

but this unfortunately blocks email for all users. Is it possible to make this work for only one user user@example.com?


The correct syntax for the transport file in you case should be (using regular expressions):

/^user@example\.com/ discard:
/.*/ :

The first line tells postfix to discard mail sent with address user@example.com, the second line tess postfix to accept everything else.

| improve this answer | |

Postfix provides 'check_sender_access' parameter. It can be used in /etc/postfix/main.cf as

smtpd_sender_restrictions = check_sender_access hash:/etc/postfix/access

To block, out going emails for test@example.com, create /etc/postfix/access with following

test@example.com REJECT

after that run below commands

postmap /etc/postfix/access
service postfix restart

If you are using sendmail as a MTA then you edit the file /etc/mail/access and add the following rule in it,

From:test@example.com   REJECT

then restart the sendmail service as,

service sendmail restart

the user 'test' should not be able to send mails.

| improve this answer | |

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.