Configuring postfix to block all emails except one email accounts
Configuring postfix to block all emails except the specified email accounts
Here is how you can configure postfix to block all emails except the specified email accounts, following the below steps:
Use Transport Mapping
Here we can tell the postfix mail server to send or disregard the emails. For this we need to edit the postfix configuration file.
Please make sure to take the backup of config files before editing. So that we can restore the original files if any errors occur while editing. You can take the backup like this
#cp -p /etc/postfix/main.cf /etc/postfix/main.cf.original
#vi /etc/postfix/main.cf
add the below line on the configuration
transport_maps = hash:/etc/postfix/transport
Now we need to edit the file /etc/postfix/transport
#vi /etc/postfix/transport
Here add the domain which we need to allow sending mail
example.com : * discard;
This will simply discard messages to any email address not of the domain example.com. If you wanted to reject with an error you’d use (set the error text to suit your needs)
You can add like this
example.com: * error: Not allowed for all domains
We can add additional domains after example.com (one line per domain).
Save the file.
Now we need to create a hash of the file (unless you used texthash in main.cf)
postmap /etc/postfix/transport
We need to reload postfix for the changes to reflect.
/etc/init.d/postfix reload
This should help you block all emails except the specified email accounts.
For any further queries talk to our Server Helpdesk Support.
We are one of the experts in providing cPanel Server Management services. We also provide other server administration works related to cPanel and in Handling cPanel servers.