Stopping Spam

Email spam can be defined as unnecessary and unwanted email received by a user that probably doesn't know the sender and never requested the communication. It is a very disruptive, costly, and widespread abuse of Internet communication standards.

Thankfully, Sendmail has made it (relatively) easy to block new spamming techniques being employed to send junk email. It even blocks many of the more usual spamming methods by default, so that you would need to consciously activate them by changing your /etc/mail/sendmail.cf file in a particular way to make your system susceptible. For example, forwarding of SMTP messages, also referred to as SMTP relaying, has been disabled by default since the 8.9 version of Sendmail. Before this change occurred, Sendmail would direct your mail host (x.org) to accept messages from one party (y.com) and send them to a different party (z.net). Now, however, you have to specifically tell Sendmail to permit a domain to relay mail through your domain. Simply edit /etc/mail/relay-domains and restart Sendmail by typing the /sbin/service sendmail restart command as root to activate the changes.

However, many times, your users may be bombarded by spam from other servers throughout the Internet beyond your control. In these instances, you can use Sendmail's access control features available through the /etc/mail/access file. As root, simply add the domains that you would like to block or specifically allow access, such as:

badspammer.com       550 Go away and don't spam us anymore
tux.badspammer.com   OK
10.0                 RELAY

Because /etc/mail/access is a database, you need to use makemap to activate your changes by recreating the database map. This is easily done by running the makemap hash /etc/mail/access < /etc/mail/access command as root.

This example shows that any email sent from badspammer.com to you would be blocked with 550 RFC 821 compliant error code and message back to the spammer, except for email send from the tux.badspammer.com sub-domain, which would be accepted. The last line shows that any email sent from the 10.0.*.* network can be relayed through your mail server.

As you might expect, this example only scratches the surface of what Sendmail can do in terms of allowing or blocking access. See the /usr/share/doc/sendmail/README.cf for more detailed information and examples.