Postfix Tips

Overview

This document contains brief notes and reminders relating to Postfix configuration.


MySql

If a 'hosts' item is not included in any of the map files, localhost is assumed.

Where localhost is configured for a Postfix service, the service will attempt to use a Unix socket, typically specified in /etc/mysql/my.cnf as /var/run/mysqld/mysqld.sock.

If the service is configured to run 'chrooted', it cannot access the socket as it is outside the chroot jail.

Three options, in order of preference...

  1. Change the MySql configuration to place the socket inside the chroot jail. This is OK as long as it does not break any other applications.

  2. Set 'hosts' to use a network connection, with 'hosts=127.0.0.1' for each map file.

  3. Run each service that can't connect to MySql outside the chroot jail by modifying master.cf.

Check you can connect with a MySql client using the same connection. e.g.

  • mysql -u root -h 127.0.0.1 -p maildb

You may need to add the following in /etc/hosts.allow

  • MYSQLD : localhost : ALLOW

Also, check your firewall configuration allows the connection, usually configured for port 3306.

-- Frank Dean - 16 Jan 2005


Setting Certificates and Keys for SMTP

  1. Create a certificate and private key as described in ApacheSecureServer#GeneratingwithOpenssl
  2. Copy the certificate and private key file to /etc/postfix/smtpd.cert and /etc/postfix/smtpd.key respectively
  3. Restart postfix

-- Frank Dean 31 Jan 2005

Testing

Create a base64 encoded authentication string

# aptitude install metamail
$ printf '\0username\0password' | mimencode 

$ telnet localhost 25
ehlo localhost
AUTH PLAIN BASE64_ENCODED_OUTPUT_FROM_ABOVE
quit

As well as checking /var/log/auth.log check /var/log/mysql.log to see the query statement being issued

Display Queued Messages

# postqueue -p

Re-Queueing Messages

Check the list of queued messages before-hand. This re-queues all messages.

# postsuper -r ALL

Deleting Queued Messages

Specific Message

# postsuper -d <MESSAGE_ID>

All Messages

# postsuper -d ALL

All Deferred Messages

# postsuper -d ALL deferred

Extract Message From Mail Queue

First hold the message:

# postsuper -h <MESSAGE_ID>

then extract it:

# postcat -qhb <MESSAGE_ID> >temp.mbx

Optionally send to a different user:

$ sendmail -f <SENDER> <RECIPIENT> <temp.mbx

Testing Using Telnet

$ telnet localhost 25
EHLO mail.sender.com
MAIL FROM: <user@localhost>
RCPT TO: <user@localhost>
DATA
subject: Test
Line one
.

Note the single period at the beginning of the line to terminate the message.


See also CourierImapTips