Monday, October 17, 2016

Mail Server


1.            What is mail server?
            A mail server (sometimes also referred to an e-mail server) is a server that handles and delivers e-mail over a network, usually over the Internet. A mail server can receive e-mails from client computers and deliver them to other mail servers. A mail server can also deliver e-mails to client computers. A client computer is normally the computer where you read your e-mails, for example your computer at home or in your office. Also an advanced mobile phone or Smartphone, with e-mail capabilities, can be regarded as a client computer in these circumstances.           
2.            How many types of mail servers available in Linux?
                There are two types of mail servers.
                (i)            Sendmail server  (default  in  RHEL - 5,  available in  6  and  7)
                (ii)           Postfix  (default  in  RHEL - 6  and  7)
                These both mail server are used to send  and  receive the mails,  but we cannot used both mail servers at a time ie., we have to use only one server at a time. These mail servers are used as  CLI  mode.  Outlook express in windows is used to send  or  receive the mails.  Thunderbird  is used to send  or  receive the mails using  GUI  mode in  Linux.  # mail   is the command used to send the mails in  CLI mode.
3.            What  are  MUA,  MTA,  SMTP,  MDA  and  MRAs?
                MUA :
                MUA  stands for  Mail  User  Agent. It is the e-mail client which we used  to  create-draft-send  emails.  Generally Microsoft  Outlook,  Thunderbird,  kmail, ....etc.,  are the examples  for  MUAs.
                MTA :
                MTA  stands for  Mail  Transfer  Agent.  It is used to transfer the messages  and  mails  between  senders  and  recipients.  Exchange,  Qmail,  Sendmail,  Postfix, ....etc.,  are the examples for  MTAs.
                SMTP:
                SMTP  stands for  Simple  Mail  Transfer  Protocol.  It is used to transfer the messages  and  mails  between  the MTAs. 
                MDA :
                MDA  stands for  Mail  Delivery  Agent.  It is a computer software component that is responsible for the delivery of e-mail messages to a local recipient's mailboxWithin the Internet mail architecture, local message delivery is achieved through a process of handling messages from the message transfer agent, and storing mail into the recipient's environment (typically a mailbox).
                MRA :
                MRA  stands for  Mail  Retrieval  Agent.  It is a computer application that retrieves or fetches e-mail from a remote mail server and works with a mail delivery agent to deliver mail to a local or remote email mailbox. MRAs may be external applications by themselves or be built into a bigger application like an MUA. Significant examples of standalone MRAs include fetchmail, getmail and retchmail.
4.            What is the profile of  mail  server?
                Package                                 :               sendmail   (in  RHEL - 5, 6 and  7)  or  postfix   (in  RHEL - 6  and  7).
                Configuration  file                                :               /etc/postfix/main.cf,   /etc/dovecot/dovecot.conf
                Log  file                                  :               /var/log/mail.log
                User's  mails  location          :               /var/spool/mail/
                root  user's  mail  location   :               /var/spool/mail/root
                Deamons                                               :               postfix
                Port  number                         :               25
5.            How to configure the mail server?
                The pre-requisite for mail server is  DNS.  ie.,  Domain  Naming  System  should be configured first.
                (i)            Check the hostname of the server by   # hostname    command.
                (ii)           Install the mail server package  by   # yum  install  postfix*   dovecot*   -y   command.
                (iii)          Open the mail configuration file and  at last type as below.
                                                # vim   /etc/postfix/main.cf
                                                myhostname  =  server9.example.com
                                                mydomain  =  example.com
                                                myorigin  =  $mydomain
                                                inet_interfaces  =  $myhostname,   localhost
                                                mydestination  =  $myhostname,   localhost.$localdomain,  localhost,  $mydomain
                                                home_mailbox  =  Maildir  /                                                                                                               (save  and  exit  this  file)
                (iv) Open  the  another configuration file  and  at last type as below.
                                                # vim   /etc/dovecot/dovecot.conf
                                                protocols  =  imap    pop3    lmtp                                                                                                       (save  and  exit  this  file)
                (v)           Restart the mail server services.
                                                # service  postfix  restart                                                                      (to restart the postfix deamon in  RHEL - 6)
                                                # service  dovecot  restart                                                                  (to restart the dovecot deamon in  RHEL - 6)
                                                # chkconfig  postfix  on                                                       (to enable  the postfix deamon at next boot in  RHEL - 6)
                                                # chkconfig  dovecot  on                                     (to enable  the dovecot deamon at next boot in  RHEL - 6)
                                                # systemctl  restart  postfix   doveco0t                           (to restart the  postfix  and  dovecot  deamons in  RHEL - 6)
                                                # systemctl  enable  postfix   dovecot                                              (to enable the  deamons at next boot in  RHEL - 6)
                (vi) Add the service to the IP tables  and  firewall.
                                In  RHEL - 6 :
                                # iptables    -A   INPUT   -i   eth0   -p   tcp   -m   tcp   --deport    25  -j    ACCEPT
                                # iptables    -A   OUTPUT   -i   eth0   -p   tcp   -m   tcp   --deport    25  -j    ACCEPT
                                # service  iptables  save
                                # service  iptables  restart
                                In  RHEL - 7 :
                                # firewall-cmd    --permanent    --add-port=25/tcp
                                # firewall-cmd    --complete-reload
                (vii) Send  a  test mail  to the user.
                                # mail    -s   testmail    raju
                                Hi  this is a test  mail
                                ok  bye... bye ....                                                                                               (exit  and  send the  mail by  Ctrl + d )
                (viii)  Login as  raju  user  and  check the mail.
                                # su  -  raju
                                    $ ls
                                    $ cd  Maildir
                                    $ ls
                                    $ cd  new
                                    $ cat  
6.            How to configure mail server as null client  in  RHEL - 7 ?
                (i)            Open the configuration file  and  at last type as below.
                                # vim   /etc/postfix/main.cf
                                relayhost  =  [client9.example.com]
                                inet_interfaces  =  loopback-only
                                mynetworks  =  127.0.0.0/8     [ : : 1]/128
                                myorigin  =  server9.example.com
                                mydestination  =
                                local_transport  =  error :  local  delivery  disabled                                                         (save  and  exit  this  file)
                (ii)           Restart the postfix deamons.
                                # systemctl  restart  postfix
                                # systemctl  enable  postfix
                (iii) Add  the  postfix  service to Firewall.
                                # firewall-cmd     --permanent     --add-port=25/tcp
                                # firewall-cmd     --complete-reload
                (iv) Send  a  test mail  to the user.
                                # mail   -s   testmail    raju   or   # mutt   -s   testmail   raju
                                  Hi  this is a test  mail
                                  ok  bye... bye ....                                                                                             (exit  and  send the  mail by  Ctrl + d )
                (v)  Login as  raju  user  and  check the mail.
                                # su  -  raju
                                    $ ls
                                    $ cd  Maildir
                                    $ ls
                                    $ cd  new
                                    $ cat  
                Other  useful  commands :
                *   To send  a  mail  to the local system,  no need to configure the mail server.
                *   To send  a  mail to the remote system,  then only we have to configure the mail server.
                # mail   raju@server9.example.com                                                  (to send the mail to the raju user of the server9)
                   type the message whatever you want                                           (press  Ctrl + d  to exit  and  send the mail)
                # su   -  raju                                                                                           (to switch to the raju user)
                $ mail                                                                                                     (to check the mails of the raju user)
                   N              abcd
                   N    efgh
                   N    ijkl
                   N    mnop                                                                                                            (there  are  four  mails  in the mail box)
                &  1                                                                                                         (to read the  1st  mail)
                   *   If  the mail is new one  then  'N'  letter  is appears  before the mail.  If  it is already seen  then there is no    letter before the mail.
                   *    press   'q'   to quit the mail utility.
                # mail  or  mutt   -s   " hello "  
                   type the matter  whatever you want                                              (press  Ctrl + d  to exit  and  send the mail to 3 users)
                $ mail                                                                                                     (to see all the mail in the mail box)
                &                                                  (to read the specified  mail by it's  number)
                &  r                                                                                                          (to send the  replay mail to that user)
                &  p                                                                                                         (to send the mail to the printer for printing)
                &  w                        (to write the contents of the mail into a file, ie., save the contents of the mail ina file)
                &  q                                                                                                         (to quit the mail box)
                &  d                                                                                                         (to delete the mail)
                &  d                                                                             (to delete the specified mail  by it's number)
                &  d  1-20                                                                                                              (to delete the mails from  1 to 20 numbers)
                # mail   -s   "hello"   @ .                 (to send the mail to the remote system)
                # mailq                                                                                                   (to see the mails in the queue)
                *   If the mail server is not configured  or  not running,  then  the sent mails will be in the  queue.
                # mail   -s   "hello"   <                  (send the mail  with attached file to                                                                                                                                                                                             the  2  users)

                # postfixcheck                                                                                (to verify the mail configuration file for  syntax  errors)

No comments:

Linux, CCNA and MCSE Questions: User Managment

Linux, CCNA and MCSE Questions: User Managment