2

I have setup an Ubuntu mail server with /etc/aliases.

In the aliases file there is an alias all: group1, group2, group3, where each of the groups is defined on its own. The problem is that due to the importance and the number of people influenced by the alias all@mydomain.com anyone in possession of this email is able to send unwanted email. The server already has some kind of spam filter, I cannot recall which one.

My question is is there a way to block all incoming mails to all@mydomain.com from any email not in /etc/aliases.

I hope this post is not a duplicate. I have looked and found similar topics but none of them seemed to provide me with a solution to my question.

Kind Regards,

Stanislav
  • 225
  • 1
  • 9

1 Answers1

1

I managed to find more information from other sources such as here, here, and here.

Finally what I did was:

1) I wrote a script called update_postfix_white_list.bash

vi /etc/postfix/update_postfix_white_list.bash

2) Inside it I added:

#Parameters {aliases, white_list} file location.
aliasesfile="/etc/aliases"
postfixwhitelistfile="/etc/postfix/rbl_whitelist"
# from aliases removed all the comments| removed all the names| found all the emails| sorted them and removed duplicates | added " OK" to each email > stored it to the "white_list" file
cut -d# ${aliasesfile} -f1 |  cut -d\: -f2| grep -EiEio '\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b'| sort -u | sed -e 's/$/ OK/' > ${postfixwhitelistfile}
# Generated the hash file for the white list
postmap ${postfixwhitelistfile}
# Restarted the postfix server
service postfix restart

3) Then I modified the main.cf settings to take into consideration the "white_list" file.

vi /etc/postfix/main.cf

4) There I added:

smtpd_recipient_restrictions =
    check_sender_access hash:/etc/postfix/rbl_whitelist
    reject

5) As a final step I changed to executable the script and I ran it.

chmod u+x "/etc/postfix/update_postfix_white_list.bash"
/etc/postfix/update_postfix_white_list.bash

Which means to check using check_sender_access if the person who send the file is in the white/black list. Do not confuse it with check_recipient_access. The command reject will reject all the mails that were not accepted by the check_sender_access.

Note1: check_client_access hash:/etc/postfix/rbl_whitelist has to be after reject_unauth_destination, but before the first blacklist if you have them in your smtpd_recipient_restrictions option, for more complex settings.

Note2: After the command reject nothing else will be checked.

Note3: If you desire you may use crontab -e and then to add @daily /etc/postfix/update_postfix_white_list.bash in order to have your server update daily your white-list automatically.

Please let me know if you have any suggestions on how to improve this.

Stanislav
  • 225
  • 1
  • 9