How to block spam email address or IP address for Sendmail spammers
Sendmail offers various options to block spam email address, domain name or IP address using access database.
The File /etc/mail/access will act as an access control for your Sendmail smtp server. Using this file you can define
- Who we accept mail from
- Who we accept relaying from
- Who we will not send to etc
Step 1 :-
You will need to check and make sure the following line exists in your sendmail configuration file /etc/mail/sendmail.cf. If not, you will need to add/append following line and Save the file.
FEATURE('access_db')dnl
Step 2:-
To block junk or spam mail, you can use following format and add required entry to the file /etc/mail/access and save the file.
username@example.com REJECT
192.168.1.105 REJECT
202.45.1.100/255.0.0.0 REJECT
Step 3 :-
Once you modified sendmail.mc or access file, you will need to regenerate /etc/mail/sendmail.cf or rebuild the access database. You can use any one of the following commands to do the same:
cd /etc/mail
make
OR
m4 /etc/mail/sendmail.mc > /etc/mail/sendmail.cf
Step 4 :-
Restart the sendmail
/etc/init.d/sendmail restart
The below options are also supported by access database
- OK for Accept email FROM: or TO: specified address
- DISCARD for Do not accept email FROM: or TO: specified address
- REJECT for Drop email with an error FROM: or TO: specified address
- HATER for Use check_mail and check_realy rules for email-
- FRIEND for Do not use check_mail and check_realy rules for email
- ERROR:ecode:etext for Drop email with specified error code (ecode) and error text message (etext).
Examples
example.com ERROR:550:Relay denied
FROM:testmail@example.net REJECT
TO:spam@test.com REJECT
Spam:abuse@ FRIEND
Connect:202.54.1.2 ERROR:5.7.1:550: Relay denied