Monday, October 1, 2012

Simple Mail service using Sendmail + Dovecot

Background:
Tools like Reviewboard, Hudson, STAF/STAX has the capability for sending email notification. Most often the office mail server would not accept emails from such tool for security reason. So whats the way out ?

Can we make use of the Linux sendmail service for this purpose ?

Solution:

Step 1:  Sendmail configuration to accept SMTP request on non-localhost address

Sendmail by default listens on 127.0.0.1:25. Configure it to listen on 0.0.0.0 in /etc/mail/sendmail.mc as follows:
Modify the line
      DAEMON_OPTIONS(`Port=smtp,Addr=127.0.0.1, Name=MTA')dnl
as
     DAEMON_OPTIONS(`Port=smtp,Addr=0.0.0.0, Name=MTA')dnl

Then restart the sendmail service
    bash$ service sendmail restart

Step 2: Setup Dovecot Service
Configure /etc/dovecot/dovecot.conf with the following

       login_trusted_networks = 172.19.0.0/16
where 172.19.0.0/16 is your LAN

Configure /etc/dovecot/conf.d/10-mail.conf with the following
       mail_location = mbox:~/mail:INBOX=/var/mail/%u
       mail_privileged_group = mail

Then restart the dovecot service
       bash$ service dovecot restart

Step 3: Setup users
Just create normal Linux users using "useradd" command.

Step 4: Setup Outlook to send and receive mails
Open the menu "Tools" - "Account Setting"

In the Add New E-mail Account window, select "Microsoft Exchange, POP3, IMAP, or HTTP" and then click Next.

Check the box "Manually configure server settings or additional server types" and click next.

Configure similar to the one below. Note dev.dmp.com is the hostname of local server where sendmail+dovecot is setup.