Saturday, November 24, 2007

Sendmail

Hi friends

This article explains the basic configuration of sendmail. In this example, i use the sendmail package from the RHEL 5 and use mailserver.example.com(192.168.10.2) and dns1.example.com(192.168.10.1) as fqdn for this mail server and dns server. Lemme give you the step by step procedure for building the sendmail server.

1. Install the sendmail package:

# yum install sendmail

2. Check the Existence of package:

# rpm -qa | grep sendmail
sendmail-cf-8.13.8-2.el5
sendmail-.13.8-2.el5

3. Services:

# chkconfig --level 345 sendmail on
# service sendmail start|stop|restart|status or
# /etc/init.d/sendmail start|stop|restart|status

4. Sendmail configuration file :

# /etc/mail/sendmail.cf //main sendmail config file
# /etc/mail/sendmail.mc //file used to edit and push the updates to the main file

All configuration changes can be done only at /etc/mail/sendmail.mc and with the help of macro push it to the file /etc/mail/sendmail.cf

5. Macro m4 :

To find the macro path
# locate cf.m4
/usr/share/sendmail-cf/m4/cf.m4
#m4 /usr/share/sendmail-cf/m4/cf.m4 /etc/mail/sendmail.mc > /etc/mail/sendmail.cf
and then restart to make the changes to take effect.

6. Disabling line in /etc/mail/sendmail.mc file:

These statements are disabled by dnl commenting.
dnl DAEMON_OPTIONS(`Port=smtp,Addr=127.0.0.1, Name=MTA')
dnl # DAEMON_OPTIONS(`Port=smtp,Addr=127.0.0.1, Name=MTA')

This statement is incorrectly disabled:
# DAEMON_OPTIONS(`Port=smtp,Addr=127.0.0.1, Name=MTA')

This statement is active:
DAEMON_OPTIONS(`Port=smtp,Addr=127.0.0.1, Name=MTA')

7. DNS Server

The proper implementation of DNS server is important before configuring the sendmail. Please test the dns name resoultion with the tools like nslookup, host and dig tool.In this eg, consider the dns1.example.com (192.168.10.1) as primary dns server.

# host dns1.example.com
dns1.example.com has address 192.168.10.1
#host mailserver.example.com
mailserver.example.com address 192.168.10.2

8. Check /etc/resolv.conf file:
make sure /etc/resolv.conf file contains the correct dns server details
# vi /etc/resolv.conf
localdomain example.com
nameserver 192.168.10.1

9. Check /etc/hosts file:
# vi /etc/hosts
127.0.0.1 mailserver.example.com localhost.localdomain localhost mailserver

10. Edit /etc/mail/sendmail.mc file:

First, using dnl disable the line like
dnl "DAEMON_OPTIONS(`Port=smtp,Addr=127.0.0.1, Name=MTA')"

Second, disable the smarthost option
dnl define(`SMART_HOST',`mail.my-site.com')

Use macro and restart the sendmail daemon

Check the local NIC card is enabled for receive all packets by
# netstat -an | grep :25 | grep tcp
tcp 0 0 0.0.0.0:25 0.0.0.0:* LISTEN

11. Edit /etc/mail/access file:

# vi /etc/mail/access
localhost.localdomain RELAY
localhost RELAY
127.0.0.1 RELAY
192.168.30 REJECT // rejects the mails from 192.168.30.0 n/w
192.168.20.5 RELAY // relay the mails from the host 192.168.20.5
192.168.10 RELAY // relay the mails from 192.168.10.0 n/w
example.com RELAY // relay the mails from the suffix example.com

12. Edit /etc/mail/local-host-names file:

add hostnames or domain names for which the sendmail accept mail for local delivery.


# vi /etc/mali/local-host-names
example.com
otherdomain.com

13. Edit /etc/mail/virtusertable file:

# vi /etc/mail/virtusertable
// first column is the target email address
// second column may be created user mailbox in the mailserver, aliase name or groupname created in the /etc/aliase or even remote email address.

logu@example.com logu // logu - local user
sonia@example.com sonia
test@example.com test
testaliase@example.com testaliase // testaliase entry created in /etc/aliase
@example.com error:nouser User Unknown // answer for other than the above user

14. Edit /etc/aliases file:

add the below lines at the bottom of the file

# vi /etc/aliases
..........
..........

#setting new aliase
testaliase: logu,test

As per virtusertable above, the mail to testaliase@example.com will go to logu@example.com and sonia@example.com.

15. Configuring POP3/IMAP :
By configuring the sendmail for pop3/imap, we will be able to acces mail from thunderbird, evolution, Outlook, etc.

First, check the existence of dovecot and services using

# chkconfig --level 345 dovecot on
# service dovecot start|stop|restart|status or
# /etc/init.d/dovecot start|stop|restart|status

Second, edit the /etc/dovecot.conf file

# vi /etc/dovecot.conf
........
//search for protocols
//protocols = imap imaps pop3 pop3s
protocols = pop3 // configure pop3 or imap as per your need
........
........

Third, test the NIC listening for pop3 using,

# netstat -a | egrep -i 'pop|imap'
tcp 0 0 *:pop3 *:* LISTEN

Fourth, use Outlook or any client tool to test the mail flow.

16. Troubleshooting via telnet:

Please refer this article in my blog.

Thanks
Logu
logu_microsoft@hotmail.com
91-98414-99143