Sendmail blocking spam email id, ips with access database

by on June 20, 2006 · 4 comments· LAST UPDATED June 20, 2006


Q. How do I block or IP address for Sendmail spammers?

A. Sendmail offers various options to block an email address, domain name or IP address using access database.

File /etc/mail/access act as an access control for your Sendmail smtp server. With this file you can define:

  1. Who we accept mail from
  2. Who we accept relaying from
  3. Who we will not send to etc


# vi /etc/mail/

Make sure following line exists in your configuration file (otherwise you need to add/append following line):


Save the file and exit to shell prompt. Now, open /etc/mail/access file:

# vi /etc/mail/access

To block junk or spam mail use following format REJECT REJECT REJECT

Save the file. Once or access file is modified, you need to regenerate /etc/mail/ or rebuild the access database. Type any one of the following commands:

# cd /etc/mail
# make


# m4 /etc/mail/ > /etc/mail/

Restart the sendmail:

# /etc/init.d/sendmail restart

Other options supported by access database

  • OK - Accept email FROM: or TO: specified address
  • DISCARD - Do not accept email FROM: or TO: specified address
  • REJECT - Drop email with an error FROM: or TO: specified address
  • HATER - Use check_mail and check_realy rules for email
  • FRIEND - Do not use check_mail and check_realy rules for email
  • ERROR:ecode:etext - Drop email with specified error code (ecode) and error text message (etext).

Examples ERROR:550:Relay denied REJECT REJECT
Spam:abuse@ FRIEND
Connect: ERROR:5.7.1:550: Relay denied

How do I test access database is working or not?
Use sendmail with -bt option as follows:

# sendmail –bt
> check_mail

OR use telnet command:

# telnet localhost 25
HELO localhost

In both case you should get relay denied error.

See also:

Tweet itFacebook itG+ itDownload PDF versionFound an error/typo on this page?

{ 4 comments… read them below or add one }

1 Asim April 7, 2009 at 6:00 pm

how can i block example@* or example*@* in sendmail access databse?


2 October 12, 2009 at 10:09 am

nice , I use to love cyberciti , great for linux ppl


3 itpatil February 4, 2010 at 4:59 pm

Thanks again :)


4 Lenny Li November 27, 2014 at 6:42 am

good reference material


Leave a Comment

Tagged as:

Previous Faq:

Next Faq: