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

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

by -
0 1523

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/sendmail.mc 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:
sendmail.cf The main sendmail configuration file.
sendmail.mc A macro that’s easier to edit, which can be used to generate a new sendmail.cf file

————————————————————————————————–

Daemon Name for SMTP                sendmail
Config file                                       /etc/mail/sendmail.mc, /etc/mail/sendmail.cf
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:     122.176.113.126
  • eth1 has local (Private) IP Address:     192.168.1.254
  • A Windows client with ip address        192.168.1.15
  • A Configured DNS server on Linux server for domain linuxgateway.in
  • 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 kvit.in.

Step1: Required Packages

Packages to be installed

  • Dovecot IMAP/POP3 server

dovecot-1.0.7-7.el5

  • Sendmail MTA
  • Sendmail-cf (M4 configuration)

sendmail-cf-8.13.8-10.el5_11
sendmail-devel-8.13.8-10.el5_11
sendmail-8.13.8-10.el5_11
sendmail-doc-8.13.8-10.el5_11

  • Squirrelmail (web based email client)

squirrelmail-1.4.8-21.el5.centos

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

MailScanner-4.85.2-3.rpm.tar.gz   or latest  download from site http://mailscanner.info

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:
122.176.113.126  mail1.linuxgateway.in

where 122.176.113.126 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.
127.0.0.1 lab localhost.localdomain localhost
::1 localhost6.localdomain6 localhost6
122.176.113.126 mail1.linuxgateway.in

——————————————————————-

#  ping  mail1.linuxgateway.in      should works …

Step3:: Setting up Mail Exchanger

After set up your domain name with domain registrar( we have already registered doamin linuxgateway.in ). 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 linuxgateway.in

  • Setup the MX record in the format  mail1.linuxgateway.in  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 mail1.linuxgateway.in with the IP address that our ISP has assigned us. i.e (122.176.113.126 )

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
> linuxgateway.in
Server:         192.168.0.155
Address:        192.168.0.155#53

Non-authoritative answer:
linuxgateway.in mail exchanger = 0    mail1.linuxgateway.in.
linuxgateway.in mail exchanger = 10  linuxgateway.in.

Authoritative answers can be found from:
linuxgateway.in nameserver = ns2.linuxdnshost.com.
linuxgateway.in nameserver = ns1.linuxdnshost.com.
linuxgateway.in internet address = 74.86.3.242
ns1.linuxdnshost.com    internet address = 74.86.3.242
ns2.linuxdnshost.com    internet address = 66.228.120.88

———————————————————————-

[root@kvit ~]# nslookup linuxgateway.in
Server: 192.168.0.155
Address: 192.168.0.155#53

Non-authoritative answer:
Name: linuxgateway.in
Address: 74.86.3.242

————————————-

[root@kvit ~]# nslookup mail1.linuxgateway.in
Server: 192.168.0.155
Address: 192.168.0.155#53

Non-authoritative answer:
Name: mail1.linuxgateway.in
Address: 122.176.113.126

————————————–

Note : This means this server ( Mailserver) having IP ADDRESS ( 122.176.113.126) is mail1.linuxgateway.in 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/sendmail.cf 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/sendmail.mc. 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/sendmail.mc   and change this lines accordingly

DAEMON_OPTIONS(`Port=smtp,Addr=127.0.0.1, Name=MTA’)dnl – change to – DAEMON_OPTIONS(`Port=smtp, Name=MTA’)
LOCAL_DOMAIN(`localhost.localdomain’)dnl                 – change to –  LOCAL_DOMAIN(`linuxgateway.in’)
dnl MASQUERADE_AS(`mydomain.com’)dnl                     – change to –  MASQUERADE_AS(`linuxgateway.in’)
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
or
m4 /etc/mail/sendmail.mc > /etc/mail/sendmail.cf
service sendmail restart


Testing Sendmail :

[root@mail1 mail]# telnet  192.168.1.254  25
Trying 192.168.1.254…
Connected to mail1.linuxgateway.in (192.168.1.254).
Escape character is ‘^]’.
220 mail1.linuxgateway.in 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          sendmail.cf          sendmail.mc.rpmsave  virtusertable
access.db       local-host-names.rpmsave  sendmail.cf.bak      spamassassin         virtusertable.db
domaintable     mailertable               sendmail.cf.rpmsave  submit.cf
domaintable.db  mailertable.db            sendmail.mc          submit.mc
helpfile        Makefile                  sendmail.mc.org      trusted-users


 

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

/etc/mail/access

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

cybersite.com      REJECT
sendmail.org        RELAY
spam@buyme.com      550 Spammers shan’t see sunlight here
192.168.200        REJECT
From:spammer@somedomain.com   REJECT
To:frienddomain.com       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 linuxgateway.in

# Check the /usr/share/doc/sendmail/README.cf file for a description
# of the format of this file. (search for access_db in that file)
# The /usr/share/doc/sendmail/README.cf is part of the sendmail-doc
# package.
#
# by default we allow relaying from localhost...
Connect:localhost.localdomain           RELAY
Connect:localhost                       RELAY
Connect:127.0.0.1                       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

 /etc/mail/local-host-names

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 openpath.in  and linuxgateway.in then the file would look like this:

/etc/mail/local-host-names

openpath.in

linuxgateway.in

Actual configuration:

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

/etc/mail/virtusertable

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@linuxgateway.in                 root
postmaster@linuxgateway.in           postmaster@archive.linuxgateway.in 
@linuxgateway.in                     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 linuxgateway.in 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 sendmail.mc file and add the following line:
FEATURE(`mailertable’)    (already there by default)

Sample configuration :

192.168.      smtp:mail.myserver.com
gmail.com   smtp:mail.anotherserver.com

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

 

/etc/mail/domaintable

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

 /etc/aliases

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.

Example:

# My itsupport
itsupport:        vikas,prabhat,vivek

or
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”
where:
/home/mailings/it-list
vikas
prabhat
vivek

 

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.
From:
#protocols = imap  pop3
To:
protocols = imap imaps pop3 pop3s

Save and exit and restart dovecot service.
service dovecot restart

Testing Dovecot:

[root@mail1 ~]#  telnet 192.168.1.254 110
Trying 192.168.1.254…
telnet: connect to address 192.168.1.254: 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 192.168.1.254 110
Trying 192.168.1.254…
Connected to mail1.linuxgateway.in (192.168.1.254).
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
/var/spool/mail
[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

http://ipaddress/webmail

here

http://192.168.1.254/webmail

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
#./conf.pl

Step 9: Domain Masquerading

If you want your mail to appear to come from vikas@linuxgateway.in  and not vikas@mail1.linuxgateway.in, then you have two choices:

1. Configure your email client, such as Outlook , to set your email address to vikas@linuxgateway.in.

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

——————–

FEATURE(always_add_domain)dnl
FEATURE(`masquerade_entire_domain')dnl
FEATURE(`masquerade_envelope')dnl
FEATURE(`allmasquerade')dnl
MASQUERADE_AS(`linuxgateway.in')dnl
MASQUERADE_DOMAIN(`linuxgateway.in.')dnl
MASQUERADE_DOMAIN(localhost)dnl
MASQUERADE_DOMAIN(localhost.localdomain)dnl
______________

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/sendmail.mc file to activate the feature:

FEATURE(`genericstable’,`hash -o /etc/mail/genericstable.db’)dnl
GENERICS_DOMAIN_FILE(`/etc/mail/generics-domains’)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

linuxgateway.in
mynewsite.in
openpath.in

 

 

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

vikas     support@linuxgateway.in

Your e-mails from vikas should now appear to come from support@linuxgateway.in

Here are some other examples:

vivek           linux-support@linuxgateway.in
prabhat         it-support@linuxgateway.in

CEO, KV IT-Solutions Pvt. Ltd. | vikas@kvit.in | 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

SIMILAR ARTICLES

0 1037

0 697

NO COMMENTS

Leave a Reply

Required Captcha *