Differences

This shows you the differences between two versions of the page.

Link to this comparison view

postfix [2015/01/19 17:46] (current)
Line 1: Line 1:
 +====== Postfix Mail Server ======
  
 +  * [[Mail Servers]]
 +  * [[SendGrid]]
 +  * [[SSMTP]]
 +  * [[pflogsumm]]
 +
 +  * [[http://​www.mail-tester.com/​|Mail Tester]] - great for seeing how to improve outgoing mail setup, check for spam, etc.
 +  * [[https://​toolbox.googleapps.com/​apps/​checkmx/​|Check MX]]
 +  * [[https://​sendgrid.com/​blog/​smtp-server-response-codes-explained/​|SMTP Response Codes]]
 +
 +Postfix is the SMTP server of choice, used to send outgoing email messages to the world.
 +==== Howto ====
 +
 +To see the mail queue:
 +
 +<​code>​mailq</​code>​
 +
 +To flush the queue and try to re-send all the messages:
 +
 +<​code>​postfix flush</​code>​
 +
 +To remove all mail from the queue:
 +
 +<​code>​postsuper -d ALL</​code>​
 +
 +To remove all mail marked as deferred in the queue:
 +
 +<​code>​postsuper -d ALL deferred</​code>​
 +
 +Display configuration
 +
 +<​code>​postconf -d</​code>​
 +
 +=== 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 ''​main.cf'':​
 +
 +<​code>​
 +canonical_maps = regexp:/​etc/​postfix/​canonical-redirect
 +</​code>​
 +
 +and for the contents of the new file, choose the user and send all mail there:
 +
 +<​code>​
 +/^.*$/ steve
 +</​code>​
 +
 +Finally, reload or restart Postfix:
 +
 +<​code>​
 +postfix reload
 +</​code>​
 +==== Source Build ====
 +
 +Build with SASL and TLS support for using a third party SMTP relay server:
 +
 +<​code>​
 +make makefiles CCARGS="​-DUSE_SASL_AUTH -DUSE_CYRUS_SASL -I/​usr/​include/​sasl -DUSE_TLS -I/​usr/​include/​openssl/"​ AUXLIBS="​-lsasl2 -lssl -lcrypto"​
 +</​code>​
 +
 +Next, run ''​make install''​. ​ The defaults will place all the binaries in ''/​usr''​ as normal.
 +
 +==== Logging ====
 +
 +Logging can be made more verbose by editing ''/​etc/​postfix/​master.cf''​ and adding ''​-v''​ to the lines containing ''​smtpd''​.
 +
 +For example:
 +
 +<​code>​
 +smtp      inet  n       ​- ​      ​n ​      ​- ​      ​- ​      smtpd -v
 +</​code>​
 +
 +==== FreeBSD ====
 +
 +<​code>​
 +/​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
 +</​code>​
 +==== Configuration ====
 +
 +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
 +
 +<​code>​
 +# INTERNET HOST AND DOMAIN NAMES
 +
 +# 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
 +
 +# SENDING MAIL
 +
 +# 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
 +
 +# RECEIVING MAIL
 +
 +# 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
 +# STANDARD_CONFIGURATION_README).
 +#
 +# The local machine is always the final destination for mail addressed
 +# to user@[the.net.work.address] 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.
 +#
 +# See also below, section "​REJECTING MAIL FOR UNKNOWN LOCAL USERS"​.
 +#
 +#​mydestination = $myhostname,​ localhost.$mydomain,​ localhost
 +#​mydestination = $myhostname,​ localhost.$mydomain,​ localhost, $mydomain
 +#​mydestination = $myhostname,​ localhost.$mydomain,​ localhost, $mydomain,
 +#       ​mail.$mydomain,​ www.$mydomain,​ ftp.$mydomain
 +</​code>​
 +
 +==== Ubuntu 12.04 ====
 +
 +<​code>​
 +# See /​usr/​share/​postfix/​main.cf.dist 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_cert_file=/​etc/​ssl/​certs/​ssl-cert-snakeoil.pem
 +smtpd_tls_key_file=/​etc/​ssl/​private/​ssl-cert-snakeoil.key
 +smtpd_use_tls=yes
 +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 = 127.0.0.0/8 [::​ffff:​127.0.0.0]/​104 [::1]/128
 +mailbox_size_limit = 0
 +recipient_delimiter = +
 +inet_interfaces = all
 +</​code>​