Replacing Sendmail With Postfix

From TykWiki
Revision as of 01:14, 5 October 2012 by Tykling (talk | contribs) (→‎Post-install Configuration)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

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]?
Would you like to activate Postfix in /etc/mail/mailer.conf [n]? y

Enabling Postfix

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:


And you can disable some sendmail specific daily maintenance routines in your
/etc/periodic.conf file:


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.

Post-install Configuration

I then go delete the default /usr/local/etc/postfix/ 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: on systems without lo0:

mynetworks_style = host
relayhost = []

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.) on systems with lo0:

inet_interfaces = localhost
relayhost = []

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.

I also run the following command to rebuild the aliases database so Postfix understands it:

$ sudo postalias /etc/aliases

Starting Postfix

Now I just need to stop Sendmail and start Postfix:

sudo /etc/rc.d/sendmail onestop


$ sudo /usr/local/etc/rc.d/postfix start