Configure Sendmail Server in CentOS/Redhat/Fedora Part-2

Configure Sendmail Server in CentOS/Redhat/Fedora Part-2

by -
0 1570
Sendmail as a client Server :

On previous part we discussed about sendmail as a standalone Server i.e. solely responsible for Sending Receiving Mails directly.  for that some important part

forward and reverse DNS  of mailserver IP should be matched  like

[[email protected] named]# nslookup


For Forward Lookup

[[email protected] named]# nslookup

Address:   <--- it is static ip of sendmail server


For reverse lookup  ( PTR or Reverse DNS ,, CAN Be done by ISP)

[[email protected] named]# nslookup

Non-authoritative answer:
Address:  <--- it is static ip of sendmail server 


Note: Forward and reverse Entry should be matched, otherwise Email May landed in Junk or bounced.
in case we don't have such setup, we should go for SMTP AUTH option i.e. Relay Emails through another 
server (SMART HOST) i.e. should be authentic server. and this sendmail server should be treated as a 
client server.

Sendmail + SMTP AUTH + SMARTHOST ( Relaying Emails Through Master Server)

Edit /etc/mail/  and modify lines

define(`SMART_HOST’, `‘)dnl
FEATURE(`authinfo’,`hash /etc/mail/client-info’)dnl

Where: is a Master server
[[email protected] named]# dig @ +short

Now we have to create /etc/mail/client-info file. and write
authentication information into this file

vim /etc/mail/client-info

vim /etc/mail/client-info “U:root” “I:[email protected]” “P:[email protected]” “U:root” “I:[email protected]” “P:******”

Where :

AuthInfo     > information for Master Server ( Smart Host)
I:[email protected]       >  One valid Email ID
P:*****                                > Password for That Email ID


to make  client-info.db  write command

makemap hash  client-info < client-info

Now Emails will be relayed through SMARTHOST i.e.

Fetchmail ( Getting mails from remote server (SMARTHOST) to sendmail server(Local Server).

Install fetchmail:

[[email protected] named]# rpm -q fetchmail
package fetchmail is not installed

[[email protected] named]#
[[email protected] named]# yum install fetchmail

fetchmail.i386 0:6.3.6-4.el5



create a user

[[email protected] named]# useradd mailadmin
[[email protected] named]# passwd mailadmin
Changing password for user mailadmin.
New UNIX password:
BAD PASSWORD: it is WAY too short
Retype new UNIX password:
passwd: all authentication tokens updated successfully.
[[email protected] named]#

Note:  Fetchmail command uses a file i.e. .fetchmailrc having crucial information of EmailIDs and Passwords, so that we will create a diffrent users here , we didnot use this user as a email user, this user is for only mail adminstration ( for fetchmail only)

create a file .fetchmailrc

[[email protected] named]# su – mailadmin
[[email protected] ~]$
[[email protected] ~]$ vi .fetchmailrc

poll proto pop3 uidl
user [email protected] pass *** is vikas here
user [email protected] pass *** is  vivek here

[[email protected] ~]$ chmod 600 .fetchmailrc
[[email protected] ~]$


run fetchmail commnd to get emails from remote server:

[[email protected] ~]$ fetchmail -a -v
fetchmail: 6.3.6 querying (protocol POP3) at Sun 17 May 2015 09:37:26 PM IST: poll started
Trying to connect to
fetchmail: POP3< +OK Dovecot ready.
fetchmail: POP3> CAPA
fetchmail: POP3< +OK
fetchmail: POP3< CAPA
fetchmail: POP3< TOP
fetchmail: POP3< UIDL
fetchmail: POP3< RESP-CODES
fetchmail: POP3< PIPELINING


command will download all mails from remote server to local server and deliver emails to respective Email Boxes.


For details about fetchmail options click here < >




Receive Emails in Mdir Format instead of Mbox

Mbox Vs Mdir  Mail Box

The Unix world has two ways of storing mail messages, the traditional mbox format and the newer maildir format. Postfix and Dovecot supports the two mail storage format so you can use any format, but I highly recommend you use the maildir format.

The Mbox Format

This is the traditional way of storing mail messages in the Unix world. In this format, a regular text file which serves as the mail user’s mailbox file is created.



<< mbox storage format





How Mbox works ?

Receiving and storing a mail

  1. Lock the mailbox.
  2. Append the header (usually “From [sender’s email address] [date and time received]“) and the mail into the mailbox file.
  3. Unlock the mailbox.

Retrieving a mail

  1. Lock the mailbox.
  2. Locate and read the mail.
  3. Update the mail status flag.
  4. Unlock the mailbox.

Deleting a mail

  1. Lock the mailbox.
  2. Move the contents of the mailbox, beginning from the position right after the mail to be    deleted until the end of the mailbox, into the position of the mail to be deleted.
  3. Reduce the size of the mailbox file by the size of the deleted mail.
  4. Unlock the mailbox.

Searching a mail

  1. Lock the mailbox.
  2. Search the mailbox.
  3. Unlock the mailbox.


  • Format is universally supported.
  • Appending a new mail into the mailbox file is fast.
  • Searching text inside a single mailbox file is fast.



  • Has file locking problems.
  • Has problems when used with network file systems.
  • Format is prone to corruption.

The Maildir Format

 This is a new way of storing mail messages. In this format, a directory usually named Maildir is created for each mail user. Under this directory are three more directories named new, cur and tmp.




<<  Maildir storage format




How Maildir works ?

Receiving and storing a mail

  1. Create a unique file in the tmp directory.
  2. Write the mail into the newly created file.
  3. Move the completely written mail into the new directory.


Retrieving a mail

  1. Locate and read the mail.
  2. Move the mail from new into the cur directory and append the mail status flag into the filename.

Deleting a mail

  1. Delete the file containing the mail.

Searching a mail

  1. Search each and every mail file.


  • Locating, retrieving and deleting a specific mail is fast.
  • Minimal to no file locking needed.
  • Can be used on network file system.
  • Immune to mailbox corruption (assuming the hardware will not fail).


  • Some filesystems may not efficiently handle a large number of small files.
  • Searching text, which requires all mail files to be opened is slow.
Configure dovecot to use Mdir Mail Format

Step 1:

#vim  /etc/procmailrc

:0 wh: msgid.log

| formail -D 1008192 $HOME/msgid.cache


Step 2:

vim /etc/dovecot.conf

mail_location =

mail_location = maildir:%/mail/

Step 3:
service dovecot restart

Note : Now we find Emails in /home/username/mail folder instead of /var/spool/mail/username , view our video for more illustration.

Setting up Cron Job to download mails in regular Interval from Remote Server

[[email protected] named]# su - mailadmin
[[email protected] ~]$ which fetchmail
[[email protected] ~]$ crontab -e
*/5 * * * * /usr/bin/fetchmail -a
crontab: installing new crontab
[[email protected] ~]$

to check cron logs

# tail -f /var/log/cron

shows us cron activity.  MAILTO=”” is used for disable cron notification in mailadmin id.

to know more about cron click here <>

Download PDF

CEO, KV IT-Solutions Pvt. Ltd. | [email protected] | 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 “


0 1672

0 1328

0 1188


Leave a Reply