MTA: Sendmail

Configuration

by ross at 17:51:43 on March 20, 2014
  • Hostname is set to internal interface name: coffin.lan
  • Will be serving mail for @example.com
  • MX record for example.com is set to mx.example.com which is one of the names of external interface
  • Mail should be delivered to mailboxes in Maildir format

Create configuration file:

# cd /etc/mail
# make

Edit configuration file: YOUR-HOSTNAME.mc

diff -u freebsd.mc coffin.lan.mc

--- freebsd.mc  2008-10-14 07:33:17.000000000 +0300
+++ coffin.lan.mc  2008-11-21 08:38:24.000000000 +0200
@@ -88,5 +88,16 @@
 define(`confBIND_OPTS', `WorkAroundBrokenAAAA')
 define(`confNO_RCPT_ACTION', `add-to-undisclosed')
 define(`confPRIVACY_FLAGS', `authwarnings,noexpn,novrfy')
+
+define(`confDOMAIN_NAME', `mx.example.com')
+MASQUERADE_AS(`example.com')
+FEATURE(`masquerade_envelope')
+FEATURE(`local_procmail')
+
 MAILER(local)
 MAILER(smtp)

Edit /etc/mail/local-host-names:

example.com

Install procmail:

# cd /usr/ports/mail/procmail
# make install clean
# rehash

Edit /usr/local/etc/procmailrc:

MAILDIR=$HOME/Maildir/
DEFAULT=$MAILDIR

Add to /etc/rc.conf:

sendmail_enable="YES"

Compile and restart:

# cd /etc/mail
# make all
# make install
# make restart

Before mail could be delivered Maildir directory should be created:

# cd /home/user
# mkdir Maildir
# mkdir Maildir/cur
# mkdir Maildir/new
# mkdir Maildir/tmp
# chown -R user:user Maildir
# chmod -R 700 Maildir

Here is a script that will create Maildir directory for every user that has a directory in /home:

#!/bin/sh

users=`pw usershow -a | awk -F: '{ print $1 }'`

for user in $users; do
        if [ -d "/home/${user}" -a ! -d "/home/${user}/Maildir" ]; then
                echo "Creating Maildir for ${user}"
                mkdir /home/${user}/Maildir
                mkdir /home/${user}/Maildir/cur
                mkdir /home/${user}/Maildir/new
                mkdir /home/${user}/Maildir/tmp
                chown -R ${user}:${user} /home/${user}/Maildir
                chmod -R 700 /home/${user}/Maildir
        fi
done

 

Comments