# Compiling Postfix with MySQL support for Mac OS X client



## BjarneDM (Nov 5, 2005)

This guide has the pre-requisite that you've installed MySQL as described here: http://www.macosx.com/forums/showthread.php?t=257966

Create and enter the folder we'll use to build from:

```
mkdir -p ~/WebServer/Postfix
cd ~/WebServer/Postfix
```
In the above folder save the following as 'postfix.bash':

```
#!/bin/bash

# usage : building.bash <version> [type]

# ${1} : version number
# ${2} : ( install | upgrade ) (default: install )

if [ ! -e postfix-${1}.tar.gz ]
then
    curl -O ftp://ftp.jaquet.dk/mirror/ftp.porcupine.org/official/postfix-${1}.tar.gz
fi

export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/libexec

rm -rf postfix-${1}
tar -zxf postfix-${1}.tar.gz
cd postfix-${1}

# everything gets installed in /Library/Postfix
# all documentation is installed
make -f Makefile.init makefiles \
    'CCARGS=-DHAS_MYSQL -I/Library/MySQL/include/mysql \
            -DDEF_CONFIG_DIR=\"/Library/Postfix/conf\" \
            -DDEF_COMMAND_DIR=\"/Library/Postfix/sbin\" \
            -DDEF_DAEMON_DIR=\"/Library/Postfix/libexec\" \
            -DDEF_QUEUE_DIR=\"/Library/Postfix/spool\" \
            -DDEF_MAILQ_PATH=\"/Library/Postfix/bin/mailq\" \
            -DDEF_NEWALIAS_PATH=\"/Library/Postfix/bin/newaliases\" \
            -DDEF_SENDMAIL_PATH=\"/Library/Postfix/sbin/sendmail\" \
            -DDEF_HTML_DIR=\"/Library/Postfix/documentation/html\" \
            -DDEF_MANPAGE_DIR=\"/Library/Postfix/documentation/man\" \
            -DDEF_README_DIR=\"/Library/Postfix/documentation/readme\" \
            ' \
    'AUXLIBS=-L/Library/MySQL/lib/mysql -lmysqlclient -lz -lm'

make

sudo SystemStarter stop Postfix

case "${2:-install}" in
    "install") #(interactive version, first time install)
        echo "interactive version, first time install)"
        echo "every setting should already have the correct default answer"
        echo "!EXCEPT! for the scratch directory to which you have to answer : "
        echo "/tmp/postfix"
        sleep 10
        sudo make install
        ;;
    "upgrade") #(non-interactive version, for upgrades)
        sudo make upgrade
        ;;
    *)
        echo ':::::::::  parameter fejl  :::::::::'
        echo 'forkert  installeringsmetode angivet'
        echo 'tilladte er: "install" el. "upgrade"'
        exit
        ;;
esac

export PATH=/Library/Postfix/sbin:$PATH

sudo postfix set-permissions
sudo SystemStarter start Postfix

tail /var/log/mail.log
```
Make the file executable: chmod o+x postfix.bash
and then either: ./postfix.bash 2.2.5 install -or- ./postfix.bash 2.2.5 upgrade

Under Tiger, Apple has done away with the Postfix StarupItem and is instead using launchd. I've never been able to get postfix and launchd to play togethere, so we'll have to 1) disable the launchd postfix service 2) create a StartupItem for Postfix.

1) disable the launchd postfix service:

```
sudo launchctl stop org.postfix.master
sudo launchctl unload -w /System/Library/LaunchDaemons/org.postfix.master.plist
```

2) creating a StartupItem for Postfix
Create the Postfix StartupItem folder:

```
sudo mkdir -p /Library/StartupItems/Postfix
```
Save the following as just 'Postfix' (remember to make it executable with 'chmod o+x Postfix'):

```
#!/bin/bash

. /etc/rc.common
export MAIL_CONFIG=/Library/Postfix/conf
export PATH=/Library/Postfix/sbin:$PATH

StartService ()
{
    if [ "${POSTFIX:=-NO-}" = "-YES-" ]; then
        ConsoleMessage "Starting mail services"
	    /Library/Postfix/sbin/postfix -c /Library/Postfix/conf start
    elif [ "${MAILSERVER:=-NO-}" = "-AUTOMATIC-" ]; then
	    /Library/Postfix/sbin/postfix-watch
    fi
}

StopService ()
{
	ConsoleMessage "Stopping Postfix mail services"
	/Library/Postfix/sbin/postfix -c /Library/Postfix/conf stop
	killall -1 postfix-watch 2> /dev/null
}

RestartService ()
{
    if [ "${POSTFIX:=-NO-}" = "-YES-" ]; then
	ConsoleMessage "Reloading Postfix configuration"
	/Library/Postfix/sbin/postfix -c /Library/Postfix/conf reload
    else
	StopService
    fi
}

RunService "$1"
```
and the follwing as 'StartupParameters.plist'

```
{
  Description   = "Postfix mail server";
  Provides      = ("Postfix");
  Requires      = ("Resolver");
  Uses          = ("Network Time", "NFS");
  Preference    = "None";
  Messages =
  {
    start = "Starting Postfix";
    stop  = "Stopping Postfix";
    restart  = "Reloading Postfix Configuration";
  };
}
```
Then append the following line to '/etc/hostconfig':

```
POSTFIX=-YES-
```


----------



## BjarneDM (Nov 15, 2005)

You'll have to modify the sendmail_path in your php.ini to be:
sendmail_path = /Library/Postfix/sbin/sendmail -t -i
in order for PHP to be able to use your version instead of the one supplied by Apple.


----------

