Monday 26 January 2015

SendMail on CentOS 6.4



----------------------------------------------------------------------------------------
 Install
Send Mail on CentOS 6.4 
----------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------
2: Stop unwamted Services or settings
----------------------------------------------------------------------------------------

# /etc/init.d/NetworkManager stop
# chkconfig NetworkManager off
Note: Make sure you have configured Network i.e. (IP Address/Netmask/Gateway/DNS)

# /etc/init.d/postfix stop
# chkconfig postfix off
# vi /etc/sysconfig/selinux
SELINUX=disabled

------------------------------------------
3:  Upgrade Kernel Version
------------------------------------------
#

yum update kernel


Reboot The Server


----------------------------------------------------------------------------------------
4: Open Necessary Ports in iptables
----------------------------------------------------------------------------------------

# vi /etc/sysconfig/iptables
-A INPUT -p tcp -m state --state NEW -m tcp --dport 25 -j ACCEPT

#/etc/init.d/iptables restart
#chkconfig iptables on


----------------------------------------------------------------------------------------
5) Install Require Packages and dependencies and verify
----------------------------------------------------------------------------------------


[root@mail-server ~]# yum install sendmail sendmail-cf




----------------------------------------------------------------------------------------
6) Edit the file /etc/mail/sendmail.mc and add the following lines. Make sure you set
   your mail server domain name where it's bolded:
----------------------------------------------------------------------------------------


Most important part is to back up the MC macro file because that generates the CF file.

[root@mail-server ~]# cd /etc/mail

[root@mail-server ~]# cp sendmail.mc sendmail.mc.original
[root@mail-server ~]# cp sendmail.cf sendmail.cf.original



[root@mail-server ~]# vi /etc/mail/sendmail.mc

MASQUERADE_AS(yourdomain.com)dnl
MASQUERADE_DOMAIN(yourdomain.com)dnl
MASQUERADE_DOMAIN(alias.yourdomain.com)dnl


In the same file /etc/mail/sendmail.mc remove the "dnl" from the beginning of the lines so it will look like this:

LOCAL_DOMAIN(`localhost.localdomain')dnl
FEATURE(masquerade_envelope)dnl
FEATURE(masquerade_entire_domain)dnl


(May B line num 119,120,121)
DAEMON_OPTIONS(`Port=smtp,Addr=127.0.0.1, Name=MTA')dnl
DAEMON_OPTIONS(`Port=smtp,Addr=xxx.xxx.x.x, Name=MTA')dnl
DAEMON_OPTIONS(`Port=smtp,Addr=xxx.xxx.xxx.xxx, Name=MTA')dnl




Note:
xxx.xxx.x.x =  Your Local IP
xxx.xxx.xxx.xxx =  Your Live IP



----------------------------------------------------------------------------------------
7) Save the file and compile it using m4:
----------------------------------------------------------------------------------------


[root@mail-server ~]# m4 /etc/mail/sendmail.mc > /etc/sendmail.cf

Send Sendmail a -HUP signal using kill or simply restart the daemon for the configuration changes to take effect:




----------------------------------------------------------------------------------------
8: Save the file and compile it using m4:
----------------------------------------------------------------------------------------


[root@mail-server ~]# service sendmail restart

Testing your configuration using sendmail
And that's it! you're done. Just send yourself a test email to make sure it is really working:

Check Sendmail Service is working or Not.

 



------------------------------------------------
[root@sendmail ]# ps ax|grep sendmail
------------------------------------------------

 9129 ?        Ss     0:00 sendmail: accepting connections
 9138 ?        Ss     0:00 sendmail: Queue runner@01:00:00 for /var/spool/clientmqueue
 9163 pts/0    S+     0:00 grep sendmail


------------------------------------------------
[root@sendmail ]# ps -aef |grep sendmail
------------------------------------------------


root      9129     1  0 16:20 ?        00:00:00 sendmail: accepting connections
smmsp     9138     1  0 16:20 ?        00:00:00 sendmail: Queue runner@01:00:00 for /var/spool/clientmqueue
root      9166  8444  0 16:22 pts/0    00:00:00 grep sendmail



------------------------------------------------
[root@sendmail ]# lsof -i :25
------------------------------------------------


COMMAND   PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
sendmail 9129 root    4u  IPv4  23017      0t0  TCP localhost:smtp (LISTEN)
sendmail 9129 root    5u  IPv4  23018      0t0  TCP sendmail:smtp (LISTEN)



Also check the maillogs if any errors.

[root@sendmail #  tail -f /var/log/maillog







----------------------------------------------------------------------------------------
9: Create a Mail User & set Password
----------------------------------------------------------------------------------------


[root@mail-server ~]# useradd --create-home -s /sbin/nologin devendra; passwd





----------------------------------------------------------------------------------------
10: Test Email with Following Script
----------------------------------------------------------------------------------------


[root@mail-server ~]# /usr/sbin/sendmail -t < mail.txt

Where the contents of the mail.txt file are:
Date: Mon Jan 26 14:52:30 2015
To: you@somewhere.com
Subject: The subject of the message
From: whatever@somewhere.com Body of message goes here





[root@mail-server ~]# vi mail.txt

Date: Mon Jan 26 14:52:30 2015
To: devendra.joshi@linukstricks.com
Subject: Test Mail From Sendmail
From: devendra@linukstricks.com Body of message goes here


Also check the maillogs

[root@sendmail #  tail -f /var/log/maillog

----------------------------------------------------------------------------------------
                    END
----------------------------------------------------------------------------------------

No comments:

Post a Comment