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

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

by -
0 1055

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

[root@mail1 named]# nslookup mail.linuxgateway.in

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

For Forward Lookup

[root@mail1 named]# nslookup mail.linuxgateway.in
Server:         8.8.8.8
Address:        8.8.8.8#53

Name:   mail1.linuxgateway.in
Address: 122.176.113.126   <--- it is static ip of sendmail server

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

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

[root@mail1 named]# nslookup mail1.kvit.in
Server:         8.8.8.8
Address:        8.8.8.8#53

Non-authoritative answer:
Name:   mail1.linuxgateway.in
Address: 122.176.113.126  <--- 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/sendmail.mc  and modify lines

define(`SMART_HOST’, `mail.linuxgaeway.in‘)dnl
define(`confAUTH_MECHANISMS’, `EXTERNAL GSSAPI DIGEST-MD5 CRAM-MD5 LOGIN PLAIN’)dnl
FEATURE(`authinfo’,`hash /etc/mail/client-info’)dnl


Where:
mail.linuxgateway.in is a Master server
[root@mail1 named]# dig @8.8.8.8 mail.linuxgateway.in +short
linuxgateway.in.
74.86.3.242

————–
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
AuthInfo:mail.shamken.in “U:root” “I:vivekpal@shamken.in” “P:india@123” “U:root” “I:vivek@linuxgateway.in” “P:******”

Where :

AuthInfo :mail.linuxgateway.in     > information for Master Server ( Smart Host)
I:vivekpal@shamken.in       >  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. mail.linuxgateway.in

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

Install fetchmail:

[root@mail1 named]# rpm -q fetchmail
package fetchmail is not installed

[root@mail1 named]#
[root@mail1 named]# yum install fetchmail
—-
—-

Installed:
fetchmail.i386 0:6.3.6-4.el5

Complete!

————————-

create a user

[root@mail1 named]# useradd mailadmin
[root@mail1 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.
[root@mail1 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

[root@mail1 named]# su – mailadmin
[mailadmin@mail1 ~]$
[mailadmin@mail1 ~]$ vi .fetchmailrc

poll mail.linuxgateway.in proto pop3 uidl
user vikas@linuxgateway.in pass *** is vikas here
user vivek@linxgateway.in pass *** is  vivek here
~

[mailadmin@mail1 ~]$ chmod 600 .fetchmailrc
[mailadmin@mail1 ~]$

————————————————

run fetchmail commnd to get emails from remote server:

[mailadmin@mail1 ~]$ fetchmail -a -v
fetchmail: 6.3.6 querying mail.linuxgateway.in (protocol POP3) at Sun 17 May 2015 09:37:26 PM IST: poll started
Trying to connect to 74.86.3.242/110...connected.
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.

mail1

 

<< 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.

Advantages

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

 

Disadvantages

  • 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.

mail2

 

 

<<  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.

Advantages

  • 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).

Disadvantages

  • 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

DEFAULT=$HOME/mail/
————————————————————————-

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

[root@mail1 named]# su - mailadmin
[mailadmin@mail1 ~]$ which fetchmail
/usr/bin/fetchmail
[mailadmin@mail1 ~]$ crontab -e
MAILTO=""
*/5 * * * * /usr/bin/fetchmail -a
crontab: installing new crontab
[mailadmin@mail1 ~]$

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 <>

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 *