Building the Postfix mailserver

Get the latest source code from, I’ve used version 2.3.3. This was the latest version when I checked. I’m compiling it with several options to help me achieve the flexibility and the security I need. I’m requiring the MySQL support for mail box maintenance, SASL for authentication and the SSL options to enable TLS support. Recently I found that PCRE support is also required if you want to use the complex filtering options in Postfix.

As a precautionary measure, you may want to backup the old Postfix executables before installing the new version. The following commands may be used as an example of how to do this (you can only do this as a root user):

cd /usr/sbin
mkdir -p
cp -p post*
cp -p /usr/bin/mailq
cp -p /usr/bin/newaliases
cp -p sendmail
cd /usr/libexec
mkdir -p
cp -Rp postfix/*

First you need to install the PCRE library (Perl Compatible Regular Expressions), to enable fancy filtering in Postfix. Download the source code from the site, I’ve used version 6.7 in my setup. You can compile and install it by running the following commands for both Intel and PowerPC based macs:



sudo make install

If you made the copy of the original Postfix and installed the PCRE library you are ready to start. Unpack the source into a directory, use the Terminal and ‘cd’ into the directory where you unpacked it. Issue the following commands as a normal user:

For Intel:

 make -f Makefile.init makefiles \
 CFLAGS='-arch i386 -isysroot /Developer/SDKs/MacOSX10.4u.sdk' \
  -I/usr/local/include/sasl \
  -DHAS_PCRE -I/usr/local/include \
  -DHAS_SSL -I/usr/include/openssl \
  -DHAS_MYSQL -I/usr/local/mysql/include' \
  AUXLIBS='-L/usr/lib -lldap -L/usr/lib -llber -L/usr/local/lib \
  -L/usr/local/lib -lpcre \
  -lssl -lsasl2 -L/usr/local/mysql/lib/mysql \
  -lmysqlclient -lz -lm'

For PowerPC:

 make -f Makefile.init makefiles \
  CFLAGS='-arch ppc -isysroot /Developer/SDKs/MacOSX10.4u.sdk' \
  -I/usr/local/include/sasl \
  -DHAS_PCRE -I/usr/local/include \
  -DHAS_SSL -I/usr/include/openssl \
  -DHAS_MYSQL -I/usr/local/mysql/include' \
  AUXLIBS='-L/usr/lib -lldap -L/usr/lib -llber -L/usr/local/lib \
  -L/usr/local/lib -lpcre \
  -lssl -lsasl2 -L/usr/local/mysql/lib/mysql \
  -lmysqlclient -lz -lm'

To compile and install Postfix for both Intel and PowerPC run:

sudo make install

For the questions that are asked at the end of the compilation accept the default values.

Please note that for the dependencies on directories I’m assuming you’ve got MySQL installed from my previous instructions. If not please check the location of the MySQL files mentioned in the configuration. You can find out which configuration on your system is active by running the command ‘mysql_config’ as documented here.

9 Responses to “Building the Postfix mailserver”

  1. Paul G Says:

    While attempting the above install, I encounter the following error:

    /usr/bin/ld: multiple definitions of symbol _SSL_write
    /usr/lib/libssl.dylib(ssl_lib.o) definition of _SSL_write
    /usr/local/mysql/lib/libmysqlclient.a(ssl.o) definition of _SSL_write in section (__TEXT,__text)
    collect2: ld returned 1 exit status
    make: *** [error] Error 1
    make: *** [update] Error 1

    I have confirmed all of the mysql settings:

    Usage: /usr/local/mysql/bin/mysql_config [OPTIONS]
    –cflags [-I/usr/local/mysql/include -Os -arch ppc -fno-common]
    –include [-I/usr/local/mysql/include]
    –libs [-L/usr/local/mysql/lib -lmysqlclient -lz -lm]
    –libs_r [-L/usr/local/mysql/lib -lmysqlclient_r -lz -lm]
    –socket [/tmp/mysql.sock]
    –port [3306]
    –version [5.0.22]
    –libmysqld-libs [-L/usr/local/mysql/lib -lmysqld -lz -lm]

    This is a fresh install of OSX and all packages are from those listed in the tutorials.

    Any suggestions?


  2. ipod-groove Says:

    hello. Paul.

    Passing the client of MySQL is wrong.

    –It is likely to write like this. –

    make -f Makefile.init makefiles \
    CFLAGS=’-arch ppc -isysroot /Developer/SDKs/MacOSX10.4u.sdk’ \
    -I/usr/local/include/sasl \
    -DHAS_SSL -I/usr/include/openssl \
    -DHAS_MYSQL -I/usr/local/mysql/include’ \
    AUXLIBS=’-L/usr/lib -lldap -L/usr/lib -llber -L/usr/local/lib \
    -lssl -lsasl2 -L/usr/local/mysql/lib \
    -lmysqlclient -lz -lm’

  3. James Brown Says:

    When trying to backup Apple Postfix, I get this:

    $ sudo cd /usr/sbin
    $ sudo mkdir -p
    $ sudo cp -p post*
    cp: is a directory (not copied).


  4. Richard5 Says:

    @James: Do the others get copied ? A directory can not be copied into itself so it’s not an real issue…

  5. Simon Says:

    I would echo the comments of ipod-groove, above. The path to the directory for the mysql libraries is incorrect above.






  6. Simon Says:

    Please ignore my ignorant comment above! As Richard quite rightly warns at the start of this tutorial, an accurate mySQL installation is key to success! I was missing the shared libraries – fatal!

  7. Richard5 Says:

    Thanks for letting me and all of us know Simon.

  8. james Says:

    Hello! This is a fantastic guide … I’m afraid I’ve been struggling with the postfix build for a day now, and can’t work out what I’m doing wrong.

    When I do:
    sudo make install

    it craps out like this:
    /usr/bin/ld: Undefined symbols:
    collect2: ld returned 1 exit status
    make: *** [master] Error 1
    make: *** [update] Error 1

    From the earlier guide, it was intimated that older installations of mysql didn’t help much with this – I completely refreshed the mysql install as per this documentation, but it’s not made any difference.

    Hoping for some help!

  9. Gringo Chaz Says:

    Postfix is up now Postfix 2.4 stable release patch 5. I’m going to attempt it and I’ll let you know how it went. Thanks again for a great tutorial.

    Did you ever cover Virtual Hosting with dynamic IP? If not I hope you get a chance soon. In the meantime… I’m googling.