Replacing Sendmail With Postfix
It is easy to replace the default FreeBSD system mailer Sendmail with Postfix from ports.
Installing Postfix
To install Postfix from ports:
sudo portmaster /usr/ports/mail/postfix
I check the TLS option but leave everything else as defaults.
During the installation Postfix asks a few questions, I answer yes to all of them:
... You need user "postfix" added to group "mail". Would you like me to add it [y]? Done. ... Would you like to activate Postfix in /etc/mail/mailer.conf [n]? y ...
Post-install Configuration
The pkg-message for Postfix contains the following information:
To enable postfix startup script please add postfix_enable="YES" in your rc.conf If you not need sendmail anymore, please add in your rc.conf: sendmail_enable="NO" sendmail_submit_enable="NO" sendmail_outbound_enable="NO" sendmail_msp_queue_enable="NO" And you can disable some sendmail specific daily maintenance routines in your /etc/periodic.conf file: daily_clean_hoststat_enable="NO" daily_status_mail_rejects_enable="NO" daily_status_include_submit_mailq="NO" daily_submit_queuerun="NO" If /etc/periodic.conf does not exist please create it and add those values.
I go enable Postfix in /etc/rc.conf
, disable Sendmail in the same file, and disable the Sendmail specific things in /etc/periodic.conf
.
I then go delete the default /usr/local/etc/postfix/main.cf
and replace it with a short one, suitable for a local system mailer. I have two versions of this "short, system-mailer only Postfix config", one is for jail hosts with no loopback interface, the other is for normal systems:
main.cf on systems without lo0:
mynetworks_style = host relayhost = [mail.skabet.cn.dom]
Note that I am using a relayhost to deliver the mail. This is neccesary because my jails have invalid hostnames. Another way to solve this problem is to use Postfix sender rewriting. I use the rewriting approach in the places where I don't have an SMTP relay handy.)
main.cf on systems with lo0:
inet_interfaces = localhost relayhost = [mail.skabet.cn.dom]
I configure systems with a loopback interface to listen on only the loopback interface. This means I don't have to care about the mynetworks
setting, since no other machines can deliver mail to the server anyway. I am also using an SMTP relay server in this example.
Starting Postfix
Now I just need to stop Sendmail and start Postfix:
sudo /etc/rc.d/sendmail onestop
..and..
$ sudo /usr/local/etc/rc.d/postfix start