NOTE. As of October 2010, I use Postfix on Mac OS X, which is hilariously simpler to configure for this same task than sendmail. These instructions should still work, but I certainly won’t be updating them if I can help it.

  1. Install SASL, which sendmail needs to authenticate at the SMTP relay.

     portinstall security/cyrus-sasl2
  2. If you don’t already have the src distributions, install them now via sysinstall(8).

  3. Recompile sendmail with SASL.

     cat >> /etc/make.conf
         SENDMAIL_CFLAGS=-I/usr/local/include/sasl -DSASL
     cd /usr/src/lib/libsmutil
     make cleandir && make obj && make
     cd /usr/src/lib/libsm
     make cleandir && make obj && make
     cd /usr/src/usr.sbin/sendmail
     make cleandir && make obj && make && make install
  4. If you want to allow a subnet to relay mail through this machine, add it to the access database.

     cat >> /etc/mail/access
         Connect:192.168 RELAY
     makemap hash /etc/mail/access < /etc/mail/access
  5. Record the credentials sendmail will use to authenticate at the SMTP relay. Replace with your SMTP relay’s hostname;, your username; *****, your password.

     cat > /etc/mail/authinfo "" "" "P:*****" "M:PLAIN"
     chmod 600 /etc/mail/authinfo
     makemap hash /etc/mail/authinfo < /etc/mail/authinfo
  6. Make sure sendmail has created the proper configuration files.

     cd /etc/mail
     make all install
  7. Configure relaying. Replace camphor with your machine’s hostname; with your SMTP relay’s hostname; with the domain of your e-mail address.

     vim /etc/mail/ # before "MAILER" lines, add:
         define(`RELAY_MAILER_ARGS', `TCP $h 587')
         FEATURE(`authinfo',`hash /etc/mail/authinfo')
  8. If you intend to submit mail while offline, disable sendmail’s DNS checks and configure it to queue mail by default. Replace camphor with your machine’s hostname.

     vim /etc/mail/ # after the lines you added in Step 7, add:
         define(`confDIRECT_SUBMISSION_MODIFIERS', `C')
         define(`confTO_QUEUEWARN', `24h')
  9. Build and load the new configuration.

     cd /etc/mail
     make all install restart
  10. Send yourself a test message. Replace with your e-mail address.

    uname -a | mail -s "uname -a"

    If you configured queueing in Step 8, tell sendmail to run its queues manually.

    sendmail -qf -Ac # clientmqueue
    sendmail -qf # mqueue
  11. Check the sendmail log.

    tail /var/log/maillog

    If all has gone well, you’ll see output like this:

    May 12 19:31:48 camphor sendmail[87306]: o4CNVmmV087306: from=cfm, size=185, class=0, nrcpts=1, msgid=<201005122331.o4CNVmmV087306@camphor>, relay=cfm@localhost
    May 12 19:31:48 camphor sm-mta[87307]: o4CNVmTG087307: from=<cfm@camphor>, size=473, class=0, nrcpts=1, msgid=<201005122331.o4CNVmmV087306@camphor>, proto=ESMTP, daemon=IPv4, relay=localhost []
    May 12 19:31:48 camphor sendmail[87306]: o4CNVmmV087306:, ctladdr=cfm (501/501), delay=00:00:00, xdelay=00:00:00, mailer=relay, pri=30185, relay=[] [], dsn=2.0.0, stat=Sent (o4CNVmTG087307 Message accepted for delivery)