Wednesday, March 22, 2006

Setting up a Sendmail Server

Few points listed to build a Sendmail Mail Server

- Before making any changes to sendmail Stop the Sendmail Service.

/etc/rc.d/init.d/sendmail stop

- Editing Sendmail configuration file using macros :

Copy to a local file

Make modifications to for your local setup
Generate from
#m4 >

Copy as your new

Here we are not editing, so you can always recreate the original by way of

#m4 >

- For Starting your Smtp Server Edit

DAEMON_OPTIONS(`Port=smtp,Addr=, Name=MTA')

Find and Copy the Above Line to

DAEMON_OPTIONS(`Port=smtp,Addr=, Name=MTA')

If you have to receive Mails From a MX pointer then you will need to Configure DNS for your domain.

You first need to make sure that your mail server's name resolves in DNS correctly. For example, if your mail server's name is sriram and it you intend for it to mostly handle mail for the domain, then must correctly resolve to the IP address of one of the mail server's interfaces. You can test this using the host command:

[root@smallfry tmp]# host has address

- MX record must point to Public IP Address of your Mail Server

/etc/hosts localhost.localdomain localhost sriram

The entry for must always be followed by the fully qualified domain name (FQDN) of the server. In the case above it would be Then you must have an entry for localhost and localhost.localdomain. Linux does not function properly if the entry in /etc/hosts doesn't also include localhost and localhost.localdomain. Finally you can add any other aliases your host may have to the end of the line.

- All Linux mail clients in your home or company need to know which server is the mail server. This is configured in the file by setting the SMART_HOST statement to include the mail server. In the example below, the mail server has been set to, the mail server for the domain.


Once this is done, you need to process the file and restart sendmail

- Determine which NICs sendmail is running on

[root@sriram tmp]# netstat -an | grep :25 | grep tcp
tcp 0 0* LISTEN

If Sendmail Listens on all Interfaces than it shows as below

[root@bigboy tmp]# netstat -an | grep :25 | grep tcp
tcp 0 0* LISTEN

More Configurations:

- The /etc/mail/relay-domains File

The /etc/mail/relay-domains file is used to determine domains from which it will relay mail. The contents of the relay-domains file should be limited to those domains that can be trusted not to originate spam.

- The /etc/mail/access File

You can make sure that only trusted PCs on your network have the ability to relay mail via your mail server by using the /etc/mail/access file.

The /etc/mail/access file has two columns. The first lists IP addresses and domains from which the mail is coming or going. The second lists the type of action to be taken when mail from these sources or destinations is received. Keywords include RELAY, REJECT, OK (not ACCEPT), and DISCARD. There is no third column to state whether the IP address or domain is the source or destination of the mail, sendmail assumes it could be either and tries to match both. All other attempted relayed mail that doesn't match any of the entries in the /etc/mail/access file, sendmail will reject.

The sample file that follows allows relaying for :

localhost.localdomain RELAY
192.168.2 RELAY RELAY

You'll then have to convert this text file into a sendmail readable database file named /etc/mail/access.db. Here are the commands you need:

[root@sriram tmp]# cd /etc/mail
[root@sriram mail]# make


#makemap hash /etc/mail/access.db < /etc/mail/access

- The /etc/mail/local-host-names File

When sendmail receives mail, it needs a way of determining whether it is responsible for the mail it receives. It uses the /etc/mail/local-host-names file to do this. This file has a list of hostnames and domains for which sendmail accepts responsibility. For example, if this mail server was to accept mail for the domains and another-site then the file would look like this:

The /etc/mail/virtusertable file

The /etc/mail/virtusertable file contains a set of simple instructions on what to do with received mail. The first column lists the target email address and the second column lists the local user's mail box, a remote email address, or a mailing list entry in the /etc/aliases file to which the email should be forwarded.

If there is no match in the virtusertable file, sendmail checks for the full email address in the /etc/aliases file. webmasters marc paul paul error:nouser User unknown

In this example, mail sent to:

> will go to local user (or mailing list) webmasters, all other mail to will go to local user marc.

> sales at will go to the sales department at

> paul and finance at goes to local user (or mailing list) paul

All other users at receive a bounce back message stating "User unknown".

After editing the /etc/mail/virtusertable file, you have to convert it into a sendmail-readable database file named /etc/mail/virtusertable.db with two commands:

[root@bigboy tmp]# cd /etc/mail

[root@bigboy mail]# make


#makemap hash /etc/mail/virtusertable.db < /etc/mail/virtusertable

If these lines look like you've seen them before, you have: They're in your all-purpose sendmail restart script.

- The /etc/aliases File

You can think of the /etc/aliases file as a mailing list file. The first column has the mailing list name (sometimes called a virtual mailbox), and the second column has the members of the mailing list separated by commas.

To start, sendmail searches the first column of the file for a match. If there is no match, then sendmail assumes the recipient is a regular user on the local server and deposits the mail in their mailbox.

If it finds a match in the first column, sendmail notes the nickname entry in the second column. It then searches for the nickname again in the first column to see if the recipient isn't on yet another mailing list.

If sendmail doesn't find a duplicate, it assumes the recipient is a regular user on the local server and deposits the mail in their mailbox.

If the recipient is a mailing list, then sendmail goes through the process all over again to determine if any of the members is on yet another list, and when it is all finished, they all get a copy of the e-mail message.

In the example that follows, you can see that mail sent to users bin, daemon, lp, shutdown, apache, named, and so on by system processes will all be sent to user (or mailing list) root. In this case, root is actually an alias for a mailing list consisting of user marc and

Note: The default /etc/aliases file installed with RedHat / Fedora has the last line of this sample commented out with a #, you may want to delete the comment and change user marc to another user. Also after editing this file, you'll have to convert it into a sendmail readable database file named /etc/aliases.db. Here is the command to do that:

[root@sriram tmp]# newaliases

# Basic system aliases -- these MUST be present.
mailer-daemon: postmaster
postmaster: root

# General redirections for pseudo accounts.
bin: root
daemon: root
abuse: root

# trap decode to catch security attacks
decode: root

# Person who should get root's mail
root: marc,

Notice that there are no spaces between the mailing list entries for root: You will get errors if you add spaces.

aliases can be very useful, here are a few more list examples for your /etc/aliases file.

Mail to "" goes to users "peter", "paul" and "mary".

# Directors of my SOHO company
directors: peter,paul,mary

Mail sent to admin-list gets sent to all the users listed in the file /home/mailings/admin-list.
# My mailing list file
admin-list: ":include:/home/mailings/admin-list"

The advantage of using mailing list files is that the admin-list file can be a file that trusted users can edit, user root is only needed to update the aliases file. Despite this, there are some problems with mail reflectors. One is that bounce messages from failed attempts to broadcast go to all users. Another is that all subscriptions and unsubscriptions have to be done manually by the mailing list administrator. If either of these are a problem for you, then consider using a mailing list manager, such as majordomo.

One important note about the /etc/aliases file: By default your system uses sendmail to mail system messages to local user root. When sendmail sends e-mail to a local user, the mail has no To: in the e-mail header. If you then use a mail client with a spam mail filtering rule to reject mail with no To: in the header, such as Outlook Express or Evolution, you may find yourself dumping legitimate mail.

The /var/log/maillog File

- Because sendmail writes all its status messages in the /var/log/maillog file, always monitor this file whenever you are doing changes. Open two TELNET, SSH, or console windows. Work in one of them and monitor the sendmail status output in the other using the command

[root@bigboy tmp]# tail -f /var/log/maillog

Fighting Spam :

- RFC-Ignorant: A valid IP address checker.

FEATURE(`dnsbl', `',`"550 Mail from " $&{client_addr} " refused. Rejected for bad WHOIS info on IP of your SMTP server - see"')

- Easynet: An open proxy list.

FEATURE(`dnsbl', `', `"550 5.7.1 ACCESS DENIED to OPEN PROXY SERVER "$&{client_name}" by DNSBL ("', `')dnl
The Open Relay Database: An open mail relay list

-The Open Relay Database: An open mail relay list.

FEATURE(`dnsbl', `', `"550 Email rejected due to sending server misconfiguration - see\#why_rejected"')dnl

- Spamcop: A spammer blacklist.

FEATURE(`dnsbl', `', `"450 Mail from " $`'&{client_addr} " refused - see"')

- Spamhaus: A spammer blacklist.

Can find more here