Configure Email from Linux Machine
Linux Version: Oracle Linux 6.7
Sendemail : smtp.gmail.com
Hostname : srv1
1) Install the rpm : sendmail, mailutils, sendmail-cf
yum install sendmail -y
yum install mailutils -y
yum install sendmail-cf -y
* To check the directory mail under /etc and the files are created.
[root@srv1]# ls -l /etc/mail
total 192
-rw-r--r--. 1 root root 469 Jul 12 2016 access
-rw-r-----. 1 root root 12288 Sep 15 13:18 access.db
-rw-r--r--. 1 root root 0 Sep 15 13:18 aliasesdb-stamp
-rw-r--r--. 1 root root 233 Jul 12 2016 domaintable
-rw-r-----. 1 root root 12288 Sep 15 13:18 domaintable.db
-rw-r--r--. 1 root root 5584 Jul 12 2016 helpfile
-rw-r--r--. 1 root root 64 Jul 12 2016 local-host-names
-rw-r--r--. 1 root root 997 Jul 12 2016 mailertable
-rw-r-----. 1 root root 12288 Sep 15 13:18 mailertable.db
-rwxr-xr-x. 1 root root 2700 Jul 12 2016 make
-rw-r--r--. 1 root root 92 Jul 12 2016 Makefile
-rw-r--r--. 1 root root 58439 Jul 12 2016 sendmail.cf
-rw-r--r--. 1 root root 7202 Jul 12 2016 sendmail.mc
-rw-r--r--. 1 root root 41521 Jul 12 2016 submit.cf
-rw-r--r--. 1 root root 941 Jul 12 2016 submit.mc
-rw-r--r--. 1 root root 127 Jul 12 2016 trusted-users
-rw-r--r--. 1 root root 1847 Jul 12 2016 virtusertable
-rw-r-----. 1 root root 12288 Sep 15 13:18 virtusertable.db
2) Backup the sendmail configuration files
[root@srv1 etc]# cd /etc/mail
[root@srv1 mail]# cp sendmail.cf sendmail.cf.orig
[root@srv1 mail]# cp sendmail.mc sendmail.mc.orig
3) Configure SMTP Authentication
[root@srv1 mail]# mkdir -m 700 -p /etc/mail/auth
[root@srv1 mail]# vi /etc/mail/auth/auth-info
Copy the entries as follow (Replace username and password)
AuthInfo:smtp.gmail.com "U:root" "I:<USERNAME>@gmail.com" "P:<PASSWORD>"
* Save the file and make database-map:
[root@srv1 auth]# makemap hash auth-info < auth-info
[root@srv1 auth]# ls -lrt #See the files are generated
total 12
-rw-r--r--. 1 root root 84 Sep 15 13:25 auth-info
-rw-r-----. 1 root root 12288 Sep 15 13:25 auth-info.db
4) Configure sendmail.mc
vi /etc/mail/sendmail.mc
Copy the following lines before first MAILER in the file
* Replace the highlighted according to your email server
define(`SMART_HOST',`smtp.gmail.com')dnl
define(`RELAY_MAILER_ARGS', `TCP $h 587')dnl
define(`ESMTP_MAILER_ARGS', `TCP $h 587')dnl
define(`confAUTH_MECHANISMS', `EXTERNAL GSSAPI DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnl
FEATURE(`authinfo',`hash /etc/mail/auth/auth-info')dnl
TRUST_AUTH_MECH(`EXTERNAL DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')
* Save the file and exit;
* Make the sendmail.cf
:
[root@srv1 mail]# m4 sendmail.mc > sendmail.cf
5) Start sendmail service
[root@srv1 mail]# sh /etc/rc.d/init.d/sendmail start
Starting sendmail: [ OK ]
Starting sm-client: [ OK ]
6) Test if the mail is working.
[root@srv1 mail]# echo 'test email from me'| mail -s TEST Email sample@gmail.com
No comments:
Post a Comment