Thursday, 24 January 2019

How to Configure SendMail / Mail via Command Line On Linux 4.x to 7.x



You should whitelist this server IP for email, after then you will follow the document.

login as: root
root@192.168.1.10's password:
Last login: Wed Sep 26 17:11:15 2018
[root@abc ~] # mail
No mail for root
 [root@abc ~] #
[root@abc ~] # su - oracle
Last login: Sat Sep 29 19:26:55 PKT 2018 from 140.1.25.65 on pts/3
[oracle@abc ~]$ mail
No mail for oracle
[oracle@abc ~] $ exit
logout
 [root@abc ~] # ls
anaconda-ks.cfg  Downloads openscap_data  Templates
Desktop          initial-setup-ks.cfg  Pictures       Videos
Documents        Music                 Public
[root@abc ~]# df -h
Filesystem      Size  Used Avail Use% Mounted on
devtmpfs        3.9G     0 3.9G   0% /dev
tmpfs           3.9G   24K 3.9G   1% /dev/shm
tmpfs           3.9G  9.1M  3.9G   1% /run
tmpfs           3.9G     0  3.9G   0% /sys/fs/cgroup
/dev/sda2        50G  4.6G   43G  10% /
/dev/sda1       488M  164M  289M  37% /boot
/dev/sdb1       220G   34G  176G  17% /u01
tmpfs           787M   72K  787M   1% /run/user/0
/dev/sr0        4.6G  4.6G     0 100% /media/cdrom
tmpfs           787M     0  787M   0% /run/user/1000
[root@abc ~]# cd /media/cdrom/
[root@abc cdrom]# cd Packages/
 [root@abc Packages]# ls *mail*
fetchmail-6.3.24-7.el7.x86_64.rpm
javamail-1.4.6-8.el7.noarch.rpm
libreport-plugin-mailx-2.1.11-38.0.1.el7.x86_64.rpm
mailcap-2.1.41-2.el7.noarch.rpm
mailman-2.1.15-24.el7.x86_64.rpm
mailx-12.5-16.el7.x86_64.rpm
pcp-pmda-mailq-3.11.8-7.el7.x86_64.rpm
pcp-pmda-sendmail-3.11.8-7.el7.x86_64.rpm
procmail-3.22-36.el7.x86_64.rpm
sendmail-8.14.7-5.el7.x86_64.rpm
sendmail-cf-8.14.7-5.el7.noarch.rpm
 [root@abc Packages] # mail
No mail for root
[root@abc Packages] # mail -s
mail: option requires an argument -- s
Usage: mail -eiIUdEFntBDNHRVv~ -T FILE -u USER -h hops -r address -s SUBJECT -a FILE -q FILE -f FILE -A ACCOUNT -b USERS -c USERS -S OPTION users
[root@abc Packages] # yum --disablerepo=\* --enablerepo=media install *sendmail*
Loaded plugins: langpacks, ulninfo
Examining pcp-pmda-sendmail-3.11.8-7.el7.x86_64.rpm: pcp-pmda-sendmail-3.11.8-7.el7.x86_64
Marking pcp-pmda-sendmail-3.11.8-7.el7.x86_64.rpm to be installed
Examining sendmail-8.14.7-5.el7.x86_64.rpm: sendmail-8.14.7-5.el7.x86_64
Marking sendmail-8.14.7-5.el7.x86_64.rpm to be installed
Examining sendmail-cf-8.14.7-5.el7.noarch.rpm: sendmail-cf-8.14.7-5.el7.noarch
Marking sendmail-cf-8.14.7-5.el7.noarch.rpm to be installed
Resolving Dependencies
--> Running transaction check
---> Package pcp-pmda-sendmail.x86_64 0:3.11.8-7.el7 will be installed
--> Processing Dependency: pcp = 3.11.8-7.el7 for package: pcp-pmda-sendmail-3.11.8-7.el7.x86_64
media                                                    | 3.6 kB     00:00
--> Processing Dependency: pcp-libs = 3.11.8-7.el7 for package: pcp-pmda-sendmail-3.11.8-7.el7.x86_64
--> Processing Dependency: libpcp.so.3(PCP_3.0)(64bit) for package: pcp-pmda-sendmail-3.11.8-7.el7.x86_64
--> Processing Dependency: libpcp_pmda.so.3(PCP_PMDA_3.0)(64bit) for package: pcp-pmda-sendmail-3.11.8-7.el7.x86_64
--> Processing Dependency: libpcp_pmda.so.3(PCP_PMDA_3.1)(64bit) for package: pcp-pmda-sendmail-3.11.8-7.el7.x86_64
--> Processing Dependency: libpcp.so.3()(64bit) for package: pcp-pmda-sendmail-3.11.8-7.el7.x86_64
--> Processing Dependency: libpcp_pmda.so.3()(64bit) for package: pcp-pmda-sendmail-3.11.8-7.el7.x86_64
---> Package sendmail.x86_64 0:8.14.7-5.el7 will be installed
--> Processing Dependency: procmail for package: sendmail-8.14.7-5.el7.x86_64
--> Processing Dependency: libhesiod.so.0()(64bit) for package: sendmail-8.14.7-5.el7.x86_64
---> Package sendmail-cf.noarch 0:8.14.7-5.el7 will be installed
--> Running transaction check
---> Package hesiod.x86_64 0:3.2.1-3.el7 will be installed
---> Package pcp.x86_64 0:3.11.8-7.el7 will be installed
--> Processing Dependency: pcp-selinux = 3.11.8-7.el7 for package: pcp-3.11.8-7.el7.x86_64
---> Package pcp-libs.x86_64 0:3.11.8-7.el7 will be installed
--> Processing Dependency: pcp-conf = 3.11.8-7.el7 for package: pcp-libs-3.11.8-7.el7.x86_64
---> Package procmail.x86_64 0:3.22-36.el7 will be installed
--> Running transaction check
---> Package pcp-conf.x86_64 0:3.11.8-7.el7 will be installed
---> Package pcp-selinux.x86_64 0:3.11.8-7.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
 Package       Arch   Version      Repository                              Size
================================================================================
Installing:
 pcp-pmda-sendmail
               x86_64 3.11.8-7.el7 /pcp-pmda-sendmail-3.11.8-7.el7.x86_64  39 k
 sendmail      x86_64 8.14.7-5.el7 /sendmail-8.14.7-5.el7.x86_64          1.7 M
 sendmail-cf   noarch 8.14.7-5.el7 /sendmail-cf-8.14.7-5.el7.noarch       938 k
Installing for dependencies:
 hesiod        x86_64 3.2.1-3.el7 media                                   29 k
 pcp           x86_64 3.11.8-7.el7 media                                  917 k
 pcp-conf      x86_64 3.11.8-7.el7 media                                   28 k
 pcp-libs      x86_64 3.11.8-7.el7 media                                  325 k
 pcp-selinux   x86_64 3.11.8-7.el7 media                                   23 k
 procmail      x86_64 3.22-36.el7  media                                  171 k

Transaction Summary
================================================================================
Install  3 Packages (+6 Dependent packages)

Total size: 4.1 M
Total download size: 1.5 M
Installed size: 7.0 M
Is this ok [y/d/N]: y
Downloading packages:
--------------------------------------------------------------------------------
Total                                              921 kB/s | 1.5 MB  00:01
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Warning: RPMDB altered outside of yum.
  Installing : hesiod-3.2.1-3.el7.x86_64                                        1/9
  Installing : pcp-conf-3.11.8-7.el7.x86_64                                 2/9
  Installing : pcp-libs-3.11.8-7.el7.x86_64                                 3/9
  Installing : pcp-selinux-3.11.8-7.el7.x86_64                              4/9
  Installing : pcp-3.11.8-7.el7.x86_64                                      5/9
  Installing : procmail-3.22-36.el7.x86_64                                  6/9
  Installing: sendmail-8.14.7-5.el7.x86_64                                 7/9
  Installing : sendmail-cf-8.14.7-5.el7.noarch                              8/9
  Installing : pcp-pmda-sendmail-3.11.8-7.el7.x86_64                        9/9
  Verifying  : sendmail-cf-8.14.7-5.el7.noarch                              1/9
  Verifying  : procmail-3.22-36.el7.x86_64                                  2/9
  Verifying  : pcp-pmda-sendmail-3.11.8-7.el7.x86_64                        3/9
  Verifying  : pcp-3.11.8-7.el7.x86_64                                      4/9
  Verifying  : sendmail-8.14.7-5.el7.x86_64                                 5/9
  Verifying  : pcp-conf-3.11.8-7.el7.x86_64                                 6/9
  Verifying  : hesiod-3.2.1-3.el7.x86_64                                    7/9
  Verifying  : pcp-libs-3.11.8-7.el7.x86_64                                 8/9
  Verifying  : pcp-selinux-3.11.8-7.el7.x86_64                              9/9

Installed:
  pcp-pmda-sendmail.x86_64 0:3.11.8-7.el7     sendmail.x86_64 0:8.14.7-5.el7
  sendmail-cf.noarch 0:8.14.7-5.el7

Dependency Installed:
  hesiod.x86_64 0:3.2.1-3.el7              pcp.x86_64 0:3.11.8-7.el7
  pcp-conf.x86_64 0:3.11.8-7.el7           pcp-libs.x86_64 0:3.11.8-7.el7
  pcp-selinux.x86_64 0:3.11.8-7.el7        procmail.x86_64 0:3.22-36.el7

Complete!
[root@abc Packages] # mail
No mail for root
[root@abc Packages] # echo 'this is message body'
this is message body
[root@abc Packages] # ls *mail*
fetchmail-6.3.24-7.el7.x86_64.rpm                    pcp-pmda-mailq-3.11.8-7.el7.x86_64.rpm
javamail-1.4.6-8.el7.noarch.rpm                      pcp-pmda-sendmail-3.11.8-7.el7.x86_64.rpm
libreport-plugin-mailx-2.1.11-38.0.1.el7.x86_64.rpm  procmail-3.22-36.el7.x86_64.rpm
mailcap-2.1.41-2.el7.noarch.rpm                      sendmail-8.14.7-5.el7.x86_64.rpm
mailman-2.1.15-24.el7.x86_64.rpm                     sendmail-cf-8.14.7-5.el7.noarch.rpm
mailx-12.5-16.el7.x86_64.rpm
[root@abc Packages] # yum --disablerepo=\* --enablerepo=media install *mail*
Loaded plugins: langpacks, ulninfo
Examining fetchmail-6.3.24-7.el7.x86_64.rpm: fetchmail-6.3.24-7.el7.x86_64
Marking fetchmail-6.3.24-7.el7.x86_64.rpm to be installed
Examining javamail-1.4.6-8.el7.noarch.rpm: javamail-1.4.6-8.el7.noarch
Marking javamail-1.4.6-8.el7.noarch.rpm to be installed
Examining libreport-plugin-mailx-2.1.11-38.0.1.el7.x86_64.rpm: libreport-plugin-mailx-2.1.11-38.0.1.el7.x86_64
libreport-plugin-mailx-2.1.11-38.0.1.el7.x86_64.rpm: does not update installed package.
Examining mailcap-2.1.41-2.el7.noarch.rpm: mailcap-2.1.41-2.el7.noarch
mailcap-2.1.41-2.el7.noarch.rpm: does not update installed package.
Examining mailman-2.1.15-24.el7.x86_64.rpm: 3:mailman-2.1.15-24.el7.x86_64
Marking mailman-2.1.15-24.el7.x86_64.rpm to be installed
Examining mailx-12.5-16.el7.x86_64.rpm: mailx-12.5-16.el7.x86_64
mailx-12.5-16.el7.x86_64.rpm: does not update installed package.
Examining pcp-pmda-mailq-3.11.8-7.el7.x86_64.rpm: pcp-pmda-mailq-3.11.8-7.el7.x86_64
Marking pcp-pmda-mailq-3.11.8-7.el7.x86_64.rpm to be installed
Examining pcp-pmda-sendmail-3.11.8-7.el7.x86_64.rpm: pcp-pmda-sendmail-3.11.8-7.el7.x86_64
pcp-pmda-sendmail-3.11.8-7.el7.x86_64.rpm: does not update installed package.
Examining procmail-3.22-36.el7.x86_64.rpm: procmail-3.22-36.el7.x86_64
procmail-3.22-36.el7.x86_64.rpm: does not update installed package.
Examining sendmail-8.14.7-5.el7.x86_64.rpm: sendmail-8.14.7-5.el7.x86_64
sendmail-8.14.7-5.el7.x86_64.rpm: does not update installed package.
Examining sendmail-cf-8.14.7-5.el7.noarch.rpm: sendmail-cf-8.14.7-5.el7.noarch
sendmail-cf-8.14.7-5.el7.noarch.rpm: does not update installed package.
Resolving Dependencies
--> Running transaction check
---> Package fetchmail.x86_64 0:6.3.24-7.el7 will be installed
---> Package javamail.noarch 0:1.4.6-8.el7 will be installed
---> Package mailman.x86_64 3:2.1.15-24.el7 will be installed
--> Processing Dependency: httpd for package: 3:mailman-2.1.15-24.el7.x86_64
media                                                                                        | 3.6 kB  00:00:00
--> Processing Dependency: python-dns for package: 3:mailman-2.1.15-24.el7.x86_64
---> Package pcp-pmda-mailq.x86_64 0:3.11.8-7.el7 will be installed
--> Running transaction check
---> Package httpd.x86_64 0:2.4.6-67.0.1.el7 will be installed
--> Processing Dependency: httpd-tools = 2.4.6-67.0.1.el7 for package: httpd-2.4.6-67.0.1.el7.x86_64
---> Package python-dns.noarch 0:1.12.0-4.20150617git465785f.el7 will be installed
--> Running transaction check
---> Package httpd-tools.x86_64 0:2.4.6-67.0.1.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=====================================================================================
 Package            Arch       Version                                Repository                               Size
=====================================================================================
Installing:
 fetchmail          x86_64     6.3.24-7.el7                           /fetchmail-6.3.24-7.el7.x86_64          2.1 M
 javamail           noarch     1.4.6-8.el7                            /javamail-1.4.6-8.el7.noarch            1.8 M
 mailman            x86_64     3:2.1.15-24.el7                        /mailman-2.1.15-24.el7.x86_64            34 M
 pcp-pmda-mailq     x86_64     3.11.8-7.el7                           /pcp-pmda-mailq-3.11.8-7.el7.x86_64      23 k
Installing for dependencies:
 httpd              x86_64     2.4.6-67.0.1.el7                       media                                   1.2 M
 httpd-tools        x86_64     2.4.6-67.0.1.el7                       media                                    87 k
 python-dns         noarch     1.12.0-4.20150617git465785f.el7        media                                   233 k

Transaction Summary
=====================================================================================
Install  4 Packages (+3 Dependent packages)

Total size: 39 M
Total download size: 1.5 M
Installed size: 42 M
Is this ok [y/d/N]: y
Downloading packages:
--------------------------------------------------------------------------------------------------------------------
Total                                                                               3.4 MB/s | 1.5 MB  00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : httpd-tools-2.4.6-67.0.1.el7.x86_64                                                              1/7
  Installing : httpd-2.4.6-67.0.1.el7.x86_64                                                                    2/7
  Installing : python-dns-1.12.0-4.20150617git465785f.el7.noarch                                                3/7
  Installing : 3:mailman-2.1.15-24.el7.x86_64                                                                   4/7
  Installing : fetchmail-6.3.24-7.el7.x86_64                                                                    5/7
  Installing : javamail-1.4.6-8.el7.noarch                                                                      6/7
  Installing : pcp-pmda-mailq-3.11.8-7.el7.x86_64                                                               7/7
  Verifying  : httpd-2.4.6-67.0.1.el7.x86_64                                                                    1/7
  Verifying  : 3:mailman-2.1.15-24.el7.x86_64                                                                   2/7
  Verifying  : pcp-pmda-mailq-3.11.8-7.el7.x86_64                                                               3/7
  Verifying  : python-dns-1.12.0-4.20150617git465785f.el7.noarch                                                4/7
  Verifying  : javamail-1.4.6-8.el7.noarch                                                                      5/7
  Verifying  : httpd-tools-2.4.6-67.0.1.el7.x86_64                                                              6/7
  Verifying  : fetchmail-6.3.24-7.el7.x86_64                                                                    7/7

Installed:
  fetchmail.x86_64 0:6.3.24-7.el7   javamail.noarch 0:1.4.6-8.el7      mailman.x86_64 3:2.1.15-24.el7
  pcp-pmda-mailq.x86_64 0:3.11.8-7.el7

Dependency Installed:
  httpd.x86_64 0:2.4.6-67.0.1.el7   httpd-tools.x86_64 0:2.4.6-67.0.1.el7
  python-dns.noarch 0:1.12.0-4.20150617git465785f.el7

Complete!
 [root@abc Packages]# sendmail
Recipient names must be specified
 [root@abc Packages]# echo "furqan"
furqan
[root@abc Packages]# echo "furqan" | sendmail furqan-hafeez@abc.com
You have mail in /var/spool/mail/root
[root@abc Packages]# cd
[root@abc ~]# cd /etc/sysconfig/
[root@abc sysconfig]# vi sendmail
[root@abc sysconfig]# ls *mail*
sendmail
[root@abc sysconfig]# telnet
bash: telnet: command not found...
[root@abc sysconfig]# cd /media/cdrom/
 [root@abc cdrom]# cd Packages/
[root@abc Packages]# ls telnet*
telnet-0.17-64.el7.x86_64.rpm  telnet-server-0.17-64.el7.x86_64.rpm
[root@abc Packages] # yum --disablerepo=\* --enablerepo=media install *telnet*
Loaded plugins: langpacks, ulninfo
Examining telnet-0.17-64.el7.x86_64.rpm: 1:telnet-0.17-64.el7.x86_64
Marking telnet-0.17-64.el7.x86_64.rpm to be installed
Examining telnet-server-0.17-64.el7.x86_64.rpm: 1:telnet-server-0.17-64.el7.x86_64
Marking telnet-server-0.17-64.el7.x86_64.rpm to be installed
Resolving Dependencies
--> Running transaction check
---> Package telnet.x86_64 1:0.17-64.el7 will be installed
---> Package telnet-server.x86_64 1:0.17-64.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved


=====================================================================================
 Package                 Arch             Version                 Repository                                   Size
=====================================================================================
Installing:
 telnet                  x86_64           1:0.17-64.el7           /telnet-0.17-64.el7.x86_64                  113 k
 telnet-server           x86_64           1:0.17-64.el7           /telnet-server-0.17-64.el7.x86_64            55 k

Transaction Summary
=====================================================================================
Install  2 Packages

Total size: 168 k
Installed size: 168 k
Is this ok [y/d/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : 1:telnet-server-0.17-64.el7.x86_64                                                               1/2
  Installing : 1:telnet-0.17-64.el7.x86_64                                                                      2/2
  Verifying  : 1:telnet-0.17-64.el7.x86_64                                                                      1/2
  Verifying  : 1:telnet-server-0.17-64.el7.x86_64                                                               2/2

Installed:
  telnet.x86_64 1:0.17-64.el7telnet-server.x86_64 1:0.17-64.el7

Complete!
[root@abc Packages]# telnet
telnet>
telnet> quit
[root@abc Packages]# echo "furqan" | sendmail furqan-hafeez@abc.com
[root@abc Packages]# echo "furqan" | sendmail furqan-hafeez@abc.com
[root@abc Packages]#
[root@abc Packages]# echo "furqan" | mail -s"Database Server - Summary of last day" backupadmin@abc.com
[root@abc Packages] #
[root@abc Packages] # systemctl list-units --type=service | grep running
  abrt-oops.service                                                                         loaded active running AB
  abrtd.service                                                                             loaded active running AB
  accounts-daemon.service                                                                   loaded active running Ac
  alsa-state.service                                                                        loaded active running Ma
  atd.service                                                                               loaded active running Jo
  auditd.service                                                                            loaded active running Se
  avahi-daemon.service                                                                      loaded active running Av
  colord.service                                                                            loaded active running Ma
  crond.service                                                                             loaded active running Co
  cups.service                                                                              loaded active running CU
  dbus.service                                                                              loaded active running D-
  gdm.service                                                                               loaded active running GN
  gssproxy.service                                                                          loaded active running GS
  irqbalance.service                                                                        loaded active running ir
  ksmtuned.service                                                                          loaded active running Ke
  libstoragemgmt.service                                                                    loaded active running li
  libvirtd.service                                                                          loaded active running Vi
  lvm2-lvmetad.service                                                                      loaded active running LV
  mcelog.service                                                                            loaded active running Ma
  ModemManager.service                                                                      loaded active running Mo
  NetworkManager.service                                                                    loaded active running Ne
  packagekit.service                                                                        loaded active running Pa
  polkit.service                                                                            loaded active running Au
  postfix.service                                                                           loaded active running Po
  rhnsd.service                                                                             loaded active running LS
  rsyslog.service                                                                           loaded active running Sy
  rtkit-daemon.service                                                                      loaded active running Re
  smartd.service                                                                            loaded active running Se
  sshd.service                                                                              loaded active running Op
  systemd-journald.service                                                                  loaded active running Jo
  systemd-logind.service                                                                    loaded active running Lo
  systemd-udevd.service                                                                     loaded active running ud
  tuned.service                                                                             loaded active running Dy
  udisks2.service                                                                           loaded active running Di
  upower.service                                                                            loaded active running Da
  wpa_supplicant.service                                                                    loaded active running WP
[root@abc Packages] # postfix start
postfix/postfix-script: fatal: the Postfix mail system is already running
[root@abc Packages] # postfix reload
postfix/postfix-script: refreshing the Postfix mail system
[root@abc Packages] # vi /etc/postfix/
access         generic        main.cf        relocated      virtual
canonical      header_checks  master.cf      transport
[root@abc Packages] # vi /etc/postfix/access
[root@abc Packages] # cd /etc/postfix/
[root@abc postfix] # ls
access canonical generic header_checks main.cf master.cf relocated transport virtual
[root@abc postfix] # postfix start
postfix/postfix-script: fatal: the Postfix mail system is already running
 [root@abc postfix] #
[root@abc postfix] # echo "furqan"
furqan
[root@abc postfix] # echo "furqan" |mail -s"DR Database Configuration Status" backupadmin@abc.com
[root@abc postfix] # echo "furqan" |mail -s"DR Database Configuration Status" backupadmin@abc.com
[root@abc postfix] # service sendmail restart
Redirecting to /bin/systemctl restart sendmail.service
[root@abc postfix] # systemctl restart sendmail.service
[root@abc postfix] # systemctl stop sendmail.service
[root@abc postfix] # systemctl start sendmail.service
[root@abc postfix] # echo "furqan" |mail -s"DR Database Configuration Status" backdm@abc.com
[root@abc postfix] # echo "furqan hafeez" |mail -s"DR Database Configuration Status" furqan-hafeez@abc.com
[root@abc postfix] #
[root@abc postfix] #
[root@abc postfix] # su - oracle
Last login: Sun Sep 30 17:54:10 PKT 2018 on pts/0
[oracle@abc ~] $ echo "furqan hafeez" |mail -s"DR Database Configuration Status" furqan-hafeez@abc.com
[oracle@abc ~] $ echo "furqan hafeez" |mail -s"DR Database Configuration Status" furqan-hafeez@abc.com
[oracle@abc ~] $ echo "furqan hafeez" |mail -s"DR Database Configuration Status" furqan-hafeez@abc.com
[oracle@abc ~] $ echo "furqan hafeez" |mail -s"DR Database Configuration Status" furqan-hafeez@abc.com
[oracle@abc ~] $ echo "furqan hafeez" |mail -s"DR Database Configuration Status" furqan-hafeez@abc.com
[oracle@abc ~] $