MTA: Mail server

From Elvanör's Technical Wiki
Jump to navigation Jump to search

Overview

  • Do not confuse the different parts of an entire mail system. The MTA (Mail Transfert Agent) is responsible for the delivery of messages across the network, whereas the MDA (Mail Delivery Agent) deliver finally the email to the user's mailbox. On some systems, the MTA and MDA are one and the same. But most software packages act as either MDA or MTA.
  • Mail servers can be very tricky about the DNS / reverse DNS configuration. In particular your mail server should have a reverse DNS configured. For more information see the wiki page about Hostnames, Domains.

Installing Qmail on OS X 10.4

  • WARNING: Qmail is not fully open-source, and has been unmaintained for years. It is recommended to use Postfix instead.
  • Issue the following commands (the following tutorial is adapted from Life with Qmail, with some OS X specific notes):
  • Download source packages, setup:
cd /usr/local/src
curl http://www.qmail.org/netqmail-1.05.tar.gz -RO
curl http://cr.yp.to/ucspi-tcp/ucspi-tcp-0.88.tar.gz -RO
curl http://cr.yp.to/daemontools/daemontools-0.76.tar.gz -RO
curl http://http.netdevice.com:9080/qmail/patch/panther.patch -RO
mkdir /var/qmail
  • Setup necessary system accounts:
nireport . /groups name gid
niload group . <<EOF
> qmail:*:2107:
> nofiles:*:2108:
> EOF
nidump group . >/etc/group
nireport . /users name uid
niload passwd . <<EOF
> alias:*:7790:2108::0:0::/var/qmail/alias:/bin/true
> qmaild:*:7791:2108::0:0::/var/qmail:/bin/true
> qmaill:*:7792:2108::0:0::/var/qmail:/bin/true
> qmailp:*:7793:2108::0:0::/var/qmail:/bin/true
> qmailq:*:7794:2107::0:0::/var/qmail:/bin/true
> qmailr:*:7795:2107::0:0::/var/qmail:/bin/true
> qmails:*:7796:2107::0:0::/var/qmail:/bin/true
> EOF
nidump passwd . >/etc/passwd
  • Compile packages (applying patches):
gunzip -cd netqmail-1.05.tar.gz | tar -xf -
cd netqmail-1.05
./collate.sh
cd netqmail-1.05
patch </usr/local/src/panther.patch
make setup check
./config
cd ../..
gunzip -cd ucspi-tcp-0.88.tar.gz |tar -xf -
cd ucspi-tcp-0.88
make setup check
cd ..
mkdir -p /package
mv daemontools-0.76.tar.gz /package
chmod 1755 /package
cd /package
gunzip -cd daemontools-0.76.tar.gz |tar -xf -
echo x >> /package/admin/daemontools-0.76/src/trypoll.c # This is a necessary patch for OS X 10.4
cd admin/daemontools-0.76
package/install
cat /etc/rc.local
csh -cf '/command/svscanboot &'
rm /etc/rc.local
mkdir /Library/StartupItems/svscanboot
cd /Library/StartupItems/svscanboot
nano svscanboot
#!/bin/sh
. /etc/rc.common
StartService( )
{
ConsoleMessage "Starting svscanboot"
csh -cf '/command/svscanboot &'
}
RunService "\$1"
chmod 755 svscanboot
nano StartupParameters.plist
{
Description = svscanboot;
Provides = (svscanboot);
Requires = (Network);
OrderPreference = None;
}
nano /var/qmail/rc
#!/bin/sh
# Using stdout for logging
# Using control/defaultdelivery from qmail-local to deliver messages by default
exec env - PATH="/var/qmail/bin:$PATH" qmail-start "`cat /var/qmail/control/defaultdelivery`"
chmod 755 /var/qmail/rc
echo ./Maildir/ >/var/qmail/control/defaultdelivery
cd /var/qmail/bin
curl http://lifewithqmail.org/qmailctl-script-dt70 -RO
mv qmailctl-script-dt70 qmailctl
chmod 755 qmailctl
ln -s /var/qmail/bin/qmailctl /usr/bin
cp -p /etc/periodic/daily/500.daily /etc/periodic/500.daily.0
sh -c "cat /etc/periodic/daily/500.daily |sed -e s/mailq/qmailctl\ queue/ >/etc/periodic/daily/500.daily"
mkdir -p /var/qmail/supervise/qmail-send/log
mkdir -p /var/qmail/supervise/qmail-smtpd/log
nano /var/qmail/supervise/qmail-send/run
#!/bin/sh
exec /var/qmail/rc
nano /var/qmail/supervise/qmail-send/log/run
#!/bin/sh
exec /usr/local/bin/setuidgid qmaill /usr/local/bin/multilog t /var/log/qmail
nano /var/qmail/supervise/qmail-smtpd/run
#!/bin/sh
QMAILDUID=`id -u qmaild`
NOFILESGID=`id -g qmaild`
MAXSMTPD=`cat /var/qmail/control/concurrencyincoming`
LOCAL=`head -1 /var/qmail/control/me`
if [ -z "$QMAILDUID" -o -z "$NOFILESGID" -o -z "$MAXSMTPD" -o -z "$LOCAL" ]; then
echo QMAILDUID, NOFILESGID, MAXSMTPD, or LOCAL is unset in
echo /var/qmail/supervise/qmail-smtpd/run
exit 1
fi
if [ ! -f /var/qmail/control/rcpthosts ]; then
echo "No /var/qmail/control/rcpthosts!"
echo "Refusing to start SMTP listener because it'll create an open relay"
exit 1
fi
exec /usr/local/bin/softlimit -m 2000000 /usr/local/bin/tcpserver -v -R -l "$LOCAL" -x /etc/tcp.smtp.cdb -c "$MAXSMTPD" -u "$QMAILDUID" -g "$NOFILESGID" 0 smtp /var/qmail/bin/qmail-smtpd 2>&1
echo 20 >/var/qmail/control/concurrencyincoming
chmod 644 /var/qmail/control/concurrencyincoming
nano /var/qmail/supervise/qmail-smtpd/log/run
#!/bin/sh
exec /usr/local/bin/setuidgid qmaill /usr/local/bin/multilog t /var/log/qmail/smtpd
chmod 755 /var/qmail/supervise/qmail-send/run
chmod 755 /var/qmail/supervise/qmail-send/log/run
chmod 755 /var/qmail/supervise/qmail-smtpd/run
chmod 755 /var/qmail/supervise/qmail-smtpd/log/run
mkdir -p /var/log/qmail/smtpd
chown qmaill /var/log/qmail /var/log/qmail/smtpd
ln -s /var/qmail/supervise/qmail-send /var/qmail/supervise/qmail-smtpd /service
echo '127.:allow,RELAYCLIENT=""' >>/etc/tcp.smtp
qmailctl cdb
mv /usr/sbin/sendmail /usr/sbin/sendmail.old
chmod 0 /usr/sbin/sendmail.old
ln -s /var/qmail/bin/sendmail /usr/sbin
# echo mary >/var/qmail/alias/.qmail-root
# echo mary >/var/qmail/alias/.qmail-postmaster
# ln -s .qmail-postmaster /var/qmail/alias/.qmail-mailer-daemon
# chmod 644 /var/qmail/alias/.qmail-root /var/qmail/alias/.qmail-postmaster
# sudo -u mary -s
% cd ~mary
% /var/qmail/bin/maildirmake Maildir
% echo ./Maildir/ >.qmail
% /Developer/Tools/SetFile -a V Maildir
% exit
# reboot
...
# qmailctl stat
/service/qmail-send: up (pid 245) 75 seconds
/service/qmail-send/log: up (pid 247) 75 seconds
/service/qmail-smtpd: up (pid 248) 75 seconds
/service/qmail-smtpd/log: up (pid 253) 75 seconds
messages in queue: 0
messages in queue but not yet preprocessed: 0