Sendmail blocking spam email id, ips with access database

Q. How do I block some1@domain.com or IP address for Sendmail spammers?

ADVERTISEMENTS

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

Configuration

# vi /etc/mail/sendmail.cf

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

FEATURE(`access_db’)dnl

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
spam@domain.com REJECT
192.168.1.100 REJECT
202.54.1.100/255.0.0.0 REJECT

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

# cd /etc/mail
# make

OR

# m4 /etc/mail/sendmail.mc > /etc/mail/sendmail.cf

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

abc.com ERROR:550:Relay denied
FROM:mail@fack.net REJECT
TO:foo@bar.com REJECT
Spam:abuse@ FRIEND
Connect:202.54.1.1 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 user@abc.com

OR use telnet command:

# telnet localhost 25
HELO localhost
MAIL FROM:user@abc.com

In both case you should get relay denied error.

See also:

🐧 Get the latest tutorials on SysAdmin, Linux/Unix, Open Source/DevOps topics:
CategoryList of Unix and Linux commands
File Managementcat
Network Utilitiesdig host ip nmap
Package Managerapk apt
Processes Managementbg chroot disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w

ADVERTISEMENTS
5 comments… add one
  • Asim Apr 7, 2009 @ 18:00

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

  • www.shopaserver.com Oct 12, 2009 @ 10:09

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

  • itpatil Feb 4, 2010 @ 16:59

    Thanks again :)

  • Lenny Li Nov 27, 2014 @ 6:42

    good reference material

  • Henry Jan 14, 2016 @ 14:54

    Hi Guys

    I am using Centos and sendmail, how do i block all outgoing emails and allow only email from my domain

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre>, <code>...</code> and <kbd>...</kbd> for code samples.