0

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?

Tommiie
  • 5,627
  • 2
  • 12
  • 46
Grzegorz
  • 1
  • 6
  • please check. might helpful- https://serverfault.com/questions/412638/block-outgoing-mail-to-specific-address-using-postfix – sanjayparmar Sep 05 '18 at 07:33

2 Answers2

0

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.

Daniele Santi
  • 2,529
  • 1
  • 25
  • 22
0

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.

sanjayparmar
  • 633
  • 8
  • 19