s40mail_sendmail

Synopsys


#
# Configuring sendmail mailer daemon
#
# Hosts file configuration
# Sendmail is a little dumb about hostname look ups and it must be able to see
# the fully qualified domain name in the hosts file.
# The OS provided hosts file doesn't offer this.

Script


set -x 
echo "%Post: SENDMAIL configuration"
mv /etc/hosts /etc/hosts-$VERSION
cat > /etc/hosts <<EOF
# Do not remove the following line, or various programs
# that require network functionality will fail.
127.0.0.1               localhost.localdomain localhost
$HOSTIP		$NODENAME.$DOMAINNAME
EOF

RELAYNET=`echo $NETWORK | cut -d"." -f1,2,3`

mv /etc/mail/sendmail.mc /etc/mail/sendmail.mc-$VERSION

# Pull the MX records, find any for our nodename and determine the priority

HOST_MX=`host -t MX $DOMAINNAME | grep $NODENAME`
PRIORITY=`echo $HOST_MX | cut -d" " -f6`

if [ "$PRIORITY" == "5" ]; then         # PRIMARY MAILSERVER

# we're going to use milters to pass mail to the virus scanner and 
# the mail scanner

# Config we pull here includes SMTP Auth and milter support
# We make a change to make it receive mail from anywhere
sed -e "s/^\(DAEMON_OPTIONS.*\)/dnl \1/"\
     /mnt/source/kickstart/mail/sendmail.mc > /etc/mail/sendmail.mc

# Makes this server the end point for our domain
cat >> /etc/mail/local-host-names <<EOF
$DOMAINNAME
EOF

# Allow relaying from the local network
cat >> /etc/mail/access <<EOF
$RELAYNET			RELAY
EOF

elif [ "$PRIORITY" == "10" ]; then      # SECONDARY MAILSERVER
# Need a configuration that will do everything the primary does

sed -e "s/^\(DAEMON_OPTIONS.*\)/dnl \1/"\
     /mnt/source/kickstart/mail/sendmail.mc > /etc/mail/sendmail.mc

cat >> /etc/mail/local-host-names <<EOF
$DOMAINNAME
EOF

# Allow relaying from the local network
cat >> /etc/mail/access <<EOF
$RELAYNET			RELAY
EOF

else                                    # ORDINARY WORKSTATION

# needs to be set up to only accept mail from the localhost
# and relay it all to the primary mailserver (local smarthost)
PRIMARYHOST=`host -t MX $DOMAINNAME | grep 5 | cut -d" " -f7`
sed -e "s/dnl \(define(\`SMART_HOST\)/\1/"\
    -e "s/smtp.your.provider/$PRIMARYHOST$DOMAINNAME/"\
     /mnt/source/kickstart/mail/sendmail.mc > /etc/mail/sendmail.mc
fi

# Now install the milters
/mnt/source/kickstart/scripts/s40mail_milters.sh

# Now configure procmail to do Maildir delivery
/mnt/source/kickstart/scripts/s40mail_procmail.sh


Examples and Testing


# mailq shows all mail in /var/mail/mqueue

# a useful way to see verbose delivery messages for mail stuck in the mailq
# sendmail -v -d8.32 -qI<messageid>
set +x




Marked up in XHTML - ©2005 Thoughtful Solutions Ltd.