Postfix Mail Server

Postfix is the SMTP server of choice, used to send outgoing email messages to the world.


To see the mail queue:


To flush the queue and try to re-send all the messages:

postfix flush

To remove all mail from the queue:

postsuper -d ALL

To remove all mail marked as deferred in the queue:

postsuper -d ALL deferred

Display configuration

postconf -d

Local Mail Only

You can setup Postfix so that it doesn't send any outgoing email at all, but instead delivers everything locally to one user account.

Add this to Postfix's

canonical_maps = regexp:/etc/postfix/canonical-redirect

and for the contents of the new file, choose the user and send all mail there:

/^.*$/ steve

Finally, reload or restart Postfix:

postfix reload

Source Build

Build with SASL and TLS support for using a third party SMTP relay server:

make makefiles CCARGS="-DUSE_SASL_AUTH -DUSE_CYRUS_SASL -I/usr/include/sasl -DUSE_TLS -I/usr/include/openssl/" AUXLIBS="-lsasl2 -lssl -lcrypto"

Next, run make install. The defaults will place all the binaries in /usr as normal.


Logging can be made more verbose by editing /etc/postfix/ and adding -v to the lines containing smtpd.

For example:

smtp      inet  n       -       n       -       -       smtpd -v


/etc/rc.d/sendmail stop
pkg_upgrade -r postfix
echo sendmail_enable="NO" >> /etc/rc.conf
echo sendmail_submit_enable="NO" >> /etc/rc.conf
echo sendmail_outbound_enable="NO" >> /etc/rc.conf
echo sendmail_msp_queue_enable="NO" >> /etc/rc.conf
echo daily_clean_hoststat_enable="NO" >> /etc/periodic.conf
echo daily_status_mail_rejects_enable="NO" >> /etc/periodic.conf
echo daily_status_include_submit_mailq="NO" >> /etc/periodic.conf
echo daily_submit_queuerun="NO" >> /etc/periodic.conf
echo postfix_enable="YES" >> /etc/rc.conf
/usr/local/etc/rc.d/postfix start


When changing the Postfix configuration, you can either run postfix reload or restart it through the init system. If the changes are significant, or if postfix check complains, then restart it with init.

A default Postfix installation has a reasonable configuration.

Some common changes are:

  • myhostname
  • mydomain
  • myorigin
  • inet_interfaces
  • mydestination
# The myhostname parameter specifies the internet hostname of this
# mail system. The default is to use the fully-qualified domain name
# from gethostname(). $myhostname is used as a default value for many
# other configuration parameters.
#myhostname = host.domain.tld
#myhostname = virtual.domain.tld

# The mydomain parameter specifies the local internet domain name.
# The default is to use $myhostname minus the first component.
# $mydomain is used as a default value for many other configuration
# parameters.
#mydomain = domain.tld

# The myorigin parameter specifies the domain that locally-posted
# mail appears to come from. The default is to append $myhostname,
# which is fine for small sites.  If you run a domain with multiple
# machines, you should (1) change this to $mydomain and (2) set up
# a domain-wide alias database that aliases each user to
# user@that.users.mailhost.
# For the sake of consistency between sender and recipient addresses,
# myorigin also specifies the default domain name that is appended
# to recipient addresses that have no @domain part.
#myorigin = $myhostname
#myorigin = $mydomain


# The inet_interfaces parameter specifies the network interface
# addresses that this mail system receives mail on.  By default,
# the software claims all active interfaces on the machine. The
# parameter also controls delivery of mail to user@[ip.address].
# See also the proxy_interfaces parameter, for network addresses that
# are forwarded to us via a proxy or network address translator.
# Note: you need to stop/start Postfix when this parameter changes.
#inet_interfaces = all
#inet_interfaces = $myhostname
#inet_interfaces = $myhostname, localhost

# The mydestination parameter specifies the list of domains that this
# machine considers itself the final destination for.
# These domains are routed to the delivery agent specified with the
# local_transport parameter setting. By default, that is the UNIX
# compatible delivery agent that lookups all recipients in /etc/passwd
# and /etc/aliases or their equivalent.
# The default is $myhostname + localhost.$mydomain.  On a mail domain
# gateway, you should also include $mydomain.
# Do not specify the names of virtual domains - those domains are
# specified elsewhere (see VIRTUAL_README).
# Do not specify the names of domains that this machine is backup MX
# host for. Specify those names via the relay_domains settings for
# the SMTP server, or use permit_mx_backup if you are lazy (see
# The local machine is always the final destination for mail addressed
# to user@[] of an interface that the mail system
# receives mail on (see the inet_interfaces parameter).
# Specify a list of host or domain names, /file/name or type:table
# patterns, separated by commas and/or whitespace. A /file/name
# pattern is replaced by its contents; a type:table is matched when
# a name matches a lookup key (the right-hand side is ignored).
# Continue long lines by starting the next line with whitespace.
#mydestination = $myhostname, localhost.$mydomain, localhost
#mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
#mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain,
#       mail.$mydomain, www.$mydomain, ftp.$mydomain

Ubuntu 12.04

# See /usr/share/postfix/ for a commented, more complete version

# Debian specific:  Specifying a file name will cause the first
# line of that file to be used as the name.  The Debian default
# is /etc/mailname.
#myorigin = /etc/mailname

smtpd_banner = $myhostname ESMTP $mail_name (Ubuntu)
biff = no

# appending .domain is the MUA's job.
append_dot_mydomain = no

# Uncomment the next line to generate "delayed mail" warnings
#delay_warning_time = 4h

readme_directory = no

# TLS parameters
smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache
smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache

# See /usr/share/doc/postfix/TLS_README.gz in the postfix-doc package for
# information on enabling SSL in the smtp client.

myhostname = ubuntu
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
mydestination = ubuntu, localhost.localdomain, localhost
relayhost = 
mynetworks = [::ffff:]/104 [::1]/128
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = all