Configure Sendmail Server in CentOS 5.x/Redhat/Fedora Part-1

Configure Sendmail Server in CentOS 5.x/Redhat/Fedora Part-1

by -
0 1891

In a Enterprise or a SOHO , email is an essential part to the business. Email is used to communicate with both internal employees and external customers. By default sendmail server allows to connect to local host only. So we should edit the /etc/mail/ file to allow connect to other hosts.The sendmail daemon is configured from a directory of files in /etc/mail and a directory of configuration files in /usr/share/sendmail-cf. There are two basic configuration files: The main sendmail configuration file. A macro that’s easier to edit, which can be used to generate a new file


Daemon Name for SMTP                sendmail
Config file                                       /etc/mail/, /etc/mail/
Port                                                 25
Daemon name for POP/IMAP          dovecot
Config File                                       /etc/dovecot.conf
Port                                                 110,143
Logfile                                             /var/log/maillog
Default Mailbox Location                /var/spool/mail


My Lab Scenario :

  • We are using two systems one linux server one windows clients.
  • My CentOS 5.4 PC has two Ethernet Interface ( eth0, eth1)
  • eth0 has static (Public) IP Address:
  • eth1 has local (Private) IP Address:
  • A Windows client with ip address
  • A Configured DNS server on Linux server for domain
  • Firewall (iptables) and SELINUX should be off on server

We suggest you to review that article and configure DNS server before start configuration of sendmail server. Once you have completed the necessary steps follow this article, or view our video carefully. we will quickly configure DNS Server for the domain

Step1: Required Packages

Packages to be installed

  • Dovecot IMAP/POP3 server


  • Sendmail MTA
  • Sendmail-cf (M4 configuration)


  • Squirrelmail (web based email client)


  • Anti spam and Anti virus configuration – MailScanner, SpamAssassin, and ClamAV

MailScanner-4.85.2-3.rpm.tar.gz   or latest  download from site

Step2: Setting up hostname

Edit your hosts file ( Very Important )

Sendmail will make use of your /etc/hosts file, so you need to modify it so that mail is routed properly.

Edit your /etc/hosts file and include a line that reads:

where is the IP address that is assigned to you by your ISP ( static IP/ Public IP).

if hostname of the server is different from this. that should be entered on similar way in /etc/hosts. Hostname of the Server should be resolvable by it’s own IP Address.


# vi /etc/hosts

# Do not remove the following line, or various programs
# that require network functionality will fail. lab localhost.localdomain localhost
::1 localhost6.localdomain6 localhost6


#  ping      should works …

Step3:: Setting up Mail Exchanger

After set up your domain name with domain registrar( we have already registered doamin ). We need to configure our Mail Exchanger (MX) record. We will do this through our DNS configutaion. After we find the page that will allow you to set up your MX record, I recommend you do the following:

Change in the domain setting of domain

  • Setup the MX record in the format  as our MX record.
  • Configure your mail exchanger with a priority of 0 (zero) means primary mailserver
  • Create a hostname/address (A RECORD) that associates with the IP address that our ISP has assigned us. i.e ( )

After  done setting this up, you can test to see if it worked by dropping to a shell prompt and issuing the following command. If your setup is correct


Testing MX

[root@linuxgateway ~]# nslookup
> set q=mx

Non-authoritative answer: mail exchanger = 0 mail exchanger = 10

Authoritative answers can be found from: nameserver = nameserver = internet address =    internet address =    internet address =


[root@kvit ~]# nslookup

Non-authoritative answer:


[root@kvit ~]# nslookup

Non-authoritative answer:


Note : This means this server ( Mailserver) having IP ADDRESS ( is and it is a primary mailserver. Please note that it may take some time for the changes you have made to propagate through DNS. If you check immediately after you make these changes and do not see your settings reflected, try a few minutes later.

Step4: Configuring sendmail

The file /etc/mail/ is the main configuration file for sendmail. This “cf file” contains the directives that sendmail will operate under. Much more friendly, however, is the file /etc/mail/ This “mc file” should be the base that you use for making all changes to sendmail’s operating parameters. Additionally, the “cf file” is created from the parameters listed in this “mc file”. CentOS has done a wonderful job creating a template for your “mc file” and as such, the bulk of the changes that need to be made are just editing directives that are already present. Below are the directives that you must search for within your “mc file” and change accordingly:

edit /etc/mail/   and change this lines accordingly

DAEMON_OPTIONS(`Port=smtp,Addr=, Name=MTA’)dnl – change to – DAEMON_OPTIONS(`Port=smtp, Name=MTA’)
LOCAL_DOMAIN(`localhost.localdomain’)dnl                 – change to –  LOCAL_DOMAIN(`’)
dnl MASQUERADE_AS(`’)dnl                     – change to –  MASQUERADE_AS(`’)
dnl FEATURE(masquerade_envelope)dnl                      – change to –  FEATURE(`masquerade_envelope’)

After you have made these changes and are back in your server’s /etc/mail directory, run the command “make -C /etc/mail”. This compiles the “cf file” based on the instructions given in your “mc file”. Each time you make a change to your “mc file”, you must re-compile your “cf” file by issuing this command.

make -C /etc/mail
m4 /etc/mail/ > /etc/mail/
service sendmail restart

Testing Sendmail :

[root@mail1 mail]# telnet  25
Connected to (
Escape character is ‘^]’.
220 ESMTP Sendmail 8.13.8/8.13.8; Sun, 17 May 2015 20:34:16 +0530

Step6: Edit necessary files in /etc/mail folder

go to /etc/mail


[root@linuxgateway mail]# ls
access          local-host-names  virtusertable
access.db       local-host-names.rpmsave      spamassassin         virtusertable.db
domaintable     mailertable     
domaintable.db  mailertable.db  
helpfile        Makefile              trusted-users


here this files are important,  have to modify for mail configuration, we already discussed for /etc/mail/ and /etc/mail/


This access database file defines which hosts or IP addresses have access to the local mail server and what kind of access they have.
options are ::

OK, which is the default option, are allowed to send mail to this host as long as the mail’s final destination is the local machine.
REJECT are rejected for all mail connections.
RELAY are allowed to send mail for any destination using this mail server.
ERROR will have their mail returned with the specified mail error.
SKIP, Sendmail will abort the current search for this entry without accepting or rejecting the mail.
QUARANTINE will have their messages held and will receive the specified text as the reason for the h

Sample configuration      REJECT        RELAY      550 Spammers shan’t see sunlight here
192.168.200        REJECT   REJECT       RELAY
Connect:friend.domain   OK
Connect:from.domain     RELAY
Connect:192.168.0    RELAY
From:good@another.dom   OK
From:another.dom        REJECT

Actual for domain

# Check the /usr/share/doc/sendmail/ file for a description
# of the format of this file. (search for access_db in that file)
# The /usr/share/doc/sendmail/ is part of the sendmail-doc
# package.
# by default we allow relaying from localhost...
Connect:localhost.localdomain           RELAY
Connect:localhost                       RELAY
Connect:                       RELAY
192.168.1                               RELAY
To configure the access database, use the format shown in the 
sample to make entries in /etc/mail/access ,Whenever this 
file is updated, update its database and restart Sendmail:
# makemap hash /etc/mail/access < /etc/mail/access
# service sendmail restart


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 then the file would look like this:


Actual configuration:

# local-host-names - include all aliases for your machine here.


This database file maps mail addresses for virtual domains and users to real mailboxes. These mailboxes can be local, remote, aliases defined in /etc/mail/aliases, or files. This allows multiple virtual domains to be hosted on one machine.

Sample configuration

a sample configuration file in /etc/mail/virtusertable  to further demonstrate its format. The following example demonstrates how to create custom entries using that format:                 root                      catchall


Actual configuration:

N/A   > discussed later


This file is processed in a first match order. When an email address matches the address on the left, it is mapped to the local mailbox listed on the right. The format of the first entry in this example maps a specific email address to a local mailbox, whereas the format of the second entry maps a specific email address to a remote mailbox. Finally, any email address from which has not matched any of the previous entries will match the last mapping and be sent to the local mailbox catchall. When creating custom entries, use this format and add them to /etc/mail/virtusertable. Whenever this file is edited, update its database and restart Sendmail:

# makemap hash /etc/mail/virtusertable < /etc/mail/virtusertable
# service sendmail restart


/etc/mail/ mailertable

mailertable allows you to route or deliver mail to different hosts. You need to use feature called FEATURE(`mailertable’) and you will have to create an external database containing the routing information for various domains. First include mailertable feature you need to edit your file and add the following line:
FEATURE(`mailertable’)    (already there by default)

Sample configuration :


Actual Configuration:

N/A   > discussed later

Now build database version of the mailertable is built using:

# makemap hash /etc/mail/mailertable < /etc/mail/mailertable
# service sendmail restart



Some sites need to use multiple domain names when transitioning from an old domain to a new one. The domaintable feature enables such transitions to operate smoothly by rewriting the old domain to the new. To begin, create a file of the form:


# vi /etc/mail/domaintable

old.domain    new.domain


Now build database version of the domaintable is built using:

# makemap hash /etc/mail/domaintable< /etc/mail/domaintable
 # service sendmail restart


The /etc/aliases file is part of sendmail. It specifies which account mail sent to an alias should really be delivered to. For example, mail to the ftp account would be sent to root’s mailbox in the configuration you show.
Multiple recipients can be specified as comma-separated lists, too.
Redirecting mail to users isn’t all that can be done. Mail can be piped to programs, too, or simply directed into a file of your choice.
Modifications to the /etc/aliases file are not complete until the newaliases command is run to build /etc/aliases.db. It is in this later form that sendmail actually uses.


# My itsupport
itsupport:        vikas,prabhat,vivek

Mail sent to itsupport  gets sent to all the users listed in the file /home/mailings/it-list.

# My mailing list file
itsupport:     “:include:/home/mailings/it-list”


Actual Configuration:

N/A  > Discussed later

Now build database version of the alias.db is built using:

# newaliases

Step 7: Setting up POP3/IMAP Server(Dovecot)

Setting up dovecot server:Incoming Mail Server Configuration (Dovecot):

Open /etc/dovecot.conf and change the following lines.
#protocols = imap  pop3
protocols = imap imaps pop3 pop3s

Save and exit and restart dovecot service.
service dovecot restart

Testing Dovecot:

[root@mail1 ~]#  telnet 110
telnet: connect to address Connection refused
telnet: Unable to connect to remote host: Connection refused

refusing connection

[root@mail1 ~]# service dovecot restart
Stopping Dovecot Imap:                                     [FAILED]
Starting Dovecot Imap:                                     [  OK  ]
[root@mail1 ~]#

Test again :

[root@mail1 ~]#  telnet 110
Connected to (
Escape character is ‘^]’.
+OK Dovcot ready.


Now dovecot is up and running. ready to get mails on mailboxes in directory /var/spool/mail

[root@mail1 mail]# pwd
[root@mail1 mail]# ls -l
total 8
-rw-rw—- 1 prabhat mail    0 May  9 23:06 prabhat
-rw——- 1 root    root 2300 May  8 23:04 root
-rw-rw—- 1 rpc     mail    0 May  6 22:40 rpc
-rw-rw—- 1 vikas   mail    0 May  9 23:06 vikas
-rw-rw—- 1 vivaek  mail    0 May  9 23:06 vivaek
-rw-rw—- 1 vivek   mail    0 May  9 23:06 vivek


Note:  We will discuss dovecot in more details in other post in this series with various option. Now dovecot is enabled with default mbox format.

Step 8: Install Squirrelmail and configuration : Webmail client

Install Squirrelmail Webmail Client:

squirrelmail2Squirrelmail is a free and open-source web based email application written in PHP. It is one of the most popular webmail package because of its speed and simplicity. With Squirrelmail you can send, receive and read your emails without an email client, just by using your web browser.

# rpm -q  squirrelmail

if not installed then >>

[root@mail1 mail]# yum install squirrelmail

it will install squirrelmail with all dependencies like (glibc,php-mbstring,glibc-common and required php components )

to open the client, open your web browser and type url



Note:  Squirrelmail is based on httpd server make sure httpd service shoulb be up and running

[root@mail1 mail]# service httpd restart
Stopping httpd:                                            [FAILED]
Starting httpd:                                            [  OK  ]
[root@mail1 mail]# chkconfig httpd on
[root@mail1 mail]#

 Tweaking Squirrelmail

go to directory

#cd /usr/share/squirrelmail/config

Step 9: Domain Masquerading

If you want your mail to appear to come from  and not, then you have two choices:

1. Configure your email client, such as Outlook , to set your email address to

2. Set up masquerading to modify the domain name of all traffic originating from and passing trough your mail server.



Change the Sender's Email Address: genericstable

Sometimes domain masquerading isn’t enough. At times you may need to change not only the domain of the sender but also the username portion of the sender’s e-mail address.With sendmail, you can change both the domain and username on a case-by-case basis using the genericstable feature:

1) Add these statements to your /etc/mail/ file to activate the feature:

FEATURE(`genericstable’,`hash -o /etc/mail/genericstable.db’)dnl


2) Create a /etc/mail/generics-domains file that is just a list of all the domains that should be inspected. Make sure the file includes your server’s canonical domain name, which you can obtain using the command:

sendmail -bt -d0.1 </dev/null

# vi /etc/mail/generics-domains



3) Create your /etc/mail/genericstable file. First sendmail searches the /etc/mail/generics-domains file for a list of domains to reverse map. It then looks at the /etc/mail/genericstable file for an individual email address from a matching domain. The format of the file is


Your e-mails from vikas should now appear to come from

Here are some other examples:


CEO, KV IT-Solutions Pvt. Ltd. | | 9810028374|
Linux Professional and an Industrial Trainer | 20 + years Experience in IT Industry

” We are born free, No Gate and Windows can snatch our freedom “

Download PDF


0 1407

0 1041

0 945


Leave a Reply

Required Captcha *