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
         SENDMAIL_LDFLAGS=-L/usr/local/lib
         SENDMAIL_LDADD=-lsasl2
         ^D
    
     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
         ^D
     makemap hash /etc/mail/access < /etc/mail/access
    
  5. Record the credentials sendmail will use to authenticate at the SMTP relay. Replace mail.panix.com with your SMTP relay’s hostname; cfm@panix.com, your username; *****, your password.

     cat > /etc/mail/authinfo
         AuthInfo:mail.panix.com "U:cfm@panix.com" "I:cfm@panix.com" "P:*****" "M:PLAIN"
         ^D
     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; mail.panix.com with your SMTP relay’s hostname; panix.com with the domain of your e-mail address.

     vim /etc/mail/camphor.mc # before "MAILER" lines, add:
         define(`SMART_HOST',`mail.panix.com')
         define(`RELAY_MAILER_ARGS', `TCP $h 587')
         define(`confAUTH_MECHANISMS', `EXTERNAL GSSAPI DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')
         FEATURE(`authinfo',`hash /etc/mail/authinfo')
         MASQUERADE_AS(`panix.com')
         FEATURE(`masquerade_envelope')
    
  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/camphor.mc # after the lines you added in Step 7, add:
         FEATURE(`accept_unresolvable_domains')
         FEATURE(`accept_unqualified_senders')
         FEATURE(`nocanonify')
         define(`confDELIVERY_MODE',`deferred')
         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 cfm@panix.com with your e-mail address.

    uname -a | mail -s "uname -a" cfm@panix.com
    

    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 [127.0.0.1]
    May 12 19:31:48 camphor sendmail[87306]: o4CNVmmV087306: to=cfm@panix.com, ctladdr=cfm (501/501), delay=00:00:00, xdelay=00:00:00, mailer=relay, pri=30185, relay=[127.0.0.1] [127.0.0.1], dsn=2.0.0, stat=Sent (o4CNVmTG087307 Message accepted for delivery)