Postfix Administration
Check the configuration and queue directories for the correct security settings and setup:
postfix check
Display all settings:
postconf
Display non-default settings:
postconf -n
Check mail queues for messages pending delivery:
mailq
Display headers and details about a message:
postcat /var/spool/postfix/deferred/message-id
Delete a message in the queue:
- mailq (to get the message-id)
- postfix stop
- find /var/spool/postfix -name message-id -print | xargs rm
- postfix start
Configuration files
There are many configuration files used by Postfix located in /etc/postfix. The two main files are:
- master.cf -- defines how/what slave daemons are called by the master daemon
- main.cf -- defines all other configuration options and files
Optional but often used configuration files are:
- alias -- rewrites recipient addresses for local delivery
- virtual -- rewrites recipient addresses for all local, virtual and remote mail destinations.
- generic -- rewrites outbound addresses
- transport -- defines how messages are delivered by email address
- access -- restrict the messages accepted by host/domain/network/address
Optional files must be converted to a postfix lookup table with postmap. For example, postmap virtual creates the lookup table "virtual.db".
Master.cf
To change the smtpd daemon to only accept mail from the localhost, set the service option for smtpd to this:
#service type ... command
localhost:smtp inet ... smtpd
To change the smtpd daemon to accept mail on port 8025 instead of 25, set the service option to this:
#service type ... command
localhost:8025 inet ... smtpd
Set up a catch-all address for a domain
Edit /etc/postfix/main.cf and add a line for the virtual map:
virtual_alias_maps = hash:/etc/postfix/virtual
Edit /etc/postfix/virtual and add the following:
###############
# local users #
###############
This e-mail address is being protected from spam bots, you need JavaScript enabled to view it
user1
This e-mail address is being protected from spam bots, you need JavaScript enabled to view it
user2
This e-mail address is being protected from spam bots, you need JavaScript enabled to view it
user3
#############
# catch-all #
#############
@domain.com catch-all
Run postmap virtual, the postfix reload. Now, all email addressed to
This e-mail address is being protected from spam bots, you need JavaScript enabled to view it
will go to the catch-all address except the explicitly defined local users.
Get BCCed on all email
Add this line to /etc/postfix/main.cf:
always_bcc = foo@user
Bypassing MX lookups for a domain
The transport map can be used to deliver certain email to a different mail server than where the MX record points. This can be useful if the mail server sits in a DMZ and needs to deliver mail to an internal mail server.
Add a line to the /etc/postfix/transport file similar to this:
# the [] skips MX lookups
foo.com smtp:[10.1.5.1]
Then, run postmap transport and postfix reload.
Filtering email based on headers
Add this line to /etc/postfix/main.cf:
header_checks = regexp:/etc/postfix/header_checks
Edit header_checks and define regular expression rules:
/^From: *@spammer.com/ REJECT
/^Subject: *mortgage*/ REJECT
/^content-(type|disposition):.*name[[:space:]]*=.*\.(exe|vbs)/
REJECT Bad attachment file name extension: $2
Above are blocks based on the From:, Subject:, and file attachment extension.
Debugging Postfix
One way to debug postfix is to increase the verbosity level on a service in the /etc/postfix/master.cf file. Add from one to three -v arguments to the end of a service name, then monitor the mail log for the additional debug messages. For example, this increases verbosity on the smtpd process:
smtp inet n - n - - smtpd -v
If you suspect problems with a remote host instead of the postfix, you can use the debug_peer_list and debug_peer_level options in /etc/postfix/main.cf. This allows you to debug only connections with specific remote hosts. The verbosity level can be set from 1 to 3. For example:
debug_peer_list = foo.com
debug_peer_level = 2
Email related RFPs
- RFC 821 (SMTP)
- RFC 822 (email message format)
- RFC 974 (mail routing)
- RFC 1855 (netiquette)