Setup Sendmail Smart Relay in FreeBSD

It’s good that to route all your outgoing email to a relay server for centralize management. Compiling Sendmail’s Smart Relay options in FreeBSD is slightly different from Linux machine. But it’s fairly easy to do so. Just follow the steps below, and I assume you already have your own email relay server to relay to.

Go to /etc/mail
run “make” command for the first time to generate “yourdomain”.cf and “yourdomain”.submit.cf / “yourdomain”.mc and “yourdomain”.submit.mc file


shell> cd /etc/mail
shell> make
shell> cp freebsd.mc "yourhostname".mc
/usr/bin/m4 -D_CF_DIR_=/usr/share/sendmail/cf/   /usr/share/sendmail/cf/m4/cf.m4 "yourhostname".mc > "yourhostname".cf
cp freebsd.submit.mc "yourhostname".submit.mc
/usr/bin/m4 -D_CF_DIR_=/usr/share/sendmail/cf/   /usr/share/sendmail/cf/m4/cf.m4 "yourhostname".submit.mc > "yourhostname"submit.cf

After mc and mf files have generated. Edit .mc file, look for line below. Change the SMART HOST to your email server’s hostname. It must be hostname and you CAN’T configure IP Address for SMART HOST.


shell> vi "yourdomain".mc

dnl define(`SMART_HOST', `your.isp.mail.server')
define(`SMART_HOST', `relay.server.hostname')

Next copy “define(`SMART_HOST’, `relay.server.hostname’)” and paste it in “yourhostname”.submit.mc. It must be placed before the line of “msp” feature.


define(`SMART_HOST', `relay.server.hostname')
FEATURE(`msp', `[127.0.0.1]')dnl

After configuration has been made, now run "make install" to generate the cf file and replace sendmail.cf and submit.cf


shell> make install
shell> /usr/bin/m4 -D_CF_DIR_=/usr/share/sendmail/cf/   /usr/share/sendmail/cf/m4/cf.m4 "yourhostname".mc >  "yourhostname".cf
install -m 444  "yourhostname".cf /etc/mail/sendmail.cf
/usr/bin/m4 -D_CF_DIR_=/usr/share/sendmail/cf/   /usr/share/sendmail/cf/m4/cf.m4  "yourhostname".submit.mc >  "yourhostname".submit.cf
install -m 444 iyot.time.com.my.submit.cf /etc/mail/submit.cf

You are basically done, now. Just restart sendmail services.


shell> /etc/rc.d/sendmail restart
shell> Cannot 'restart' sendmail. Set sendmail_enable to YES in /etc/rc.conf or use 'onerestart' instead of 'restart'.
Stopping sendmail_submit.
Waiting for PIDS: 64903.

Ignore the line to change sendmail_enable to YES if your server just do email submit and it doesn't act as incoming email.