Postfix

From QNAPedia
Revision as of 18:13, 16 June 2015 by Admin (talk | contribs) (Created page with "= Postfix = When trying to use a QNAP as mailserver, one can decide to use the available QNAP-provided mailservers ... whatever the benefits of this approach, it is often no...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Postfix

When trying to use a QNAP as mailserver, one can decide to use the available QNAP-provided mailservers ... whatever the benefits of this approach, it is often not sufficient. For example it is not possible, to use ldap-based authentification together with an IMAP-server.

Postfix without an IMAP or POP3-server is not very valuable, so you might want to have a look at Dovecot_Compilation as well.

Compile Postfix

IPKG

First install ipkg. Then install a number of needed packages:

ipkg install autoconf automake bash binutils bzip2 coreutils cyrus-sasl cyrus-sasl-libs diffutils findutils \
gawk gcc gdbm gnutls gnutls-dev grep groff gzip libc-dev libdb libdb52 libgcrypt libstdc++ make man ncurses \
ncursesw openldap openldap-libs openssl openssl-dev pcre perl readline sed tar zlib

Fix Environment

Then make sure, that '/opt/bin' and '/opt/sbin' are FIRST in $PATH

export PATH=/opt/bin:/opt/sbin:$PATH

Then fix a *terribly* annoying bug in the postfix makefile (it checks for db.h in /usr/include and NOT in the given include-directories)

ln -s /opt/include /usr/include

Then add freshly installed libraries to the list of available ones

echo /opt/lib >> /etc/ld.so.conf
ldconfig

And you need some user and group for postfix, e.g. by running

adduser -S mail
addgroup maildrop

Compile

Then compile:

export CCARGS='-I/opt/include -L/opt/lib -DHAS_LDAP -DDEF_COMMAND_DIR=\"/opt/sbin\" \
-I/opt/include/sasl -DUSE_SASL_AUTH -DUSE_CYRUS_SASL \
-DHAS_SSL -I/opt/include/openssl -DUSE_TLS\
-DDEF_CONFIG_DIR=\"/opt/etc/postfix\" -DDEF_DAEMON_DIR=\"/opt/libexec/postfix\" -DDEF_DATA_DIR=\"/opt/var/lib/postfix\" \
-DDEF_MAILQ_PATH=\"/usr/bin/mailq\" -DDEF_HTML_DIR=\"/opt/share/doc/postfix/html\" -DDEF_MANPAGE_DIR=\"/opt/man\" \
-DDEF_NEWALIAS_PATH=\"/opt/bin/newaliases\" -DDEF_QUEUE_DIR=\"/opt/var/spool/postfix\" \
-DDEF_README_DIR=\"/opt/share/doc/postfix/readme\" -DDEF_SENDMAIL_PATH=\"/opt/sbin/sendmail\"'
export AUXLIBS='-llber -lldap -lsasl2 -L/opt/lib/sasl2 -lcrypto -lssl'
make tidy
make -f Makefile.init makefiles CCARGS="$CCARGS" AUXLIBS="$AUXLIBS"
make

Then fix the makedefs and postinstall-scripts to use /opt/bin/bash as shell. Then go through post-install.sh and fix mentions of 'root' to 'admin' - yes, the postfix-makefiles are screwed up big time.

And afterwards run make install (kills existing configuration) or make upgrade (keeps and needs existing configuration), depending on your needs.

Common problems

Nearly every error is due to either forgetting to install libraries/ipkg-packages, typos in the install commands, a faulty PATH (e.g. /bin preceeding /opt/bin), missing changes to /etc/ld.so.conf or (in some cases) hard-coded pathes in postfix.

  • If configure fails e.g. with a syntax-error spawn by gawk or awk, your PATH is defective and the pre-installed QNAP versions of sed or gawk are used. Please fix your path.
  • If make fails with an error like "object name conflicts", you probably don't have a real sort installed - or (again) your PATH is defective.
  • Running postfix throws errors mentioning invalid usernames ('root' is hardcoded in several places, QNAP uses 'admin' insted, fix libexec/postfix/postfix-script) or busybox-errors (add the correct PATH to libexec/postfix/postfix-script)
  • If "make install" or "make upgrade" fails with a find-error (e.g. displaying busyboy-logo), you might check your PATH again - or remove /usr/bin/find and link it to /opt/bin/find
mv /usr/bin/find /usr/bin/find.bb
ln -s /opt/bin/find /usr/bin/find

To test your path, you can run

which sed
which find
[etc]

And don't forget: Changes to /etc are often not permanent and need to be repeated after rebooting your QNAP. If you start a new shell (e.g. by writing a compile-script for postfix), you probably have to redefine e.g. $PATH. And changes to $PATH don't mean anything, if installation scripts start new shells or use hardcoded pathes (both of which postfix is doing).

Links

You might want to have a look at the Postfix-Documenation or at e.g. this tutorial.