Setting up Email Sending with Postfix

We have Linux servers that need to be able to send mail, but do not need to run an SMTP receiver.

Install the postfix and mailutils Debian packages on the Linux server.

DEBIAN_FRONTEND='noninteractive' apt-get install -y -q --force-yes postfix

If you do not do that, but do a regular apt-get, selecting "no configuration" will simplify these instructions, which have been handed down and successfully used for a couple of generations.

After you modify /etc/postfix/, be sure to run /etc/init.d/postfix reload, or the equivalent service command.

You must modify /etc/postfix/ to ensure it includes something like:

myhostname =
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
myorigin = /etc/mailname
mydestination = 
relayhost =
# Duh, shouldn't relayhost imply a connection cache?
smtp_connection_cache_on_demand = yes
smtp_connection_cache_destinations = $relayhost
smtp_connection_cache_time_limit = 60s
mynetworks = [::ffff:]/104 [::1]/128
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = loopback-only
inet_protocols = ipv4

Make sure the relayhost (mx.cs in this example) lists the server you've just set up in its list of mail clients (used to be in /software/sendmail/config/local/clients; for sendmail packages it will be /etc/mail/local-host-names ). While different references to the same host may work, the one used should be "generic" in nature, to allow for ease of changing the specific name in future by simply changing DNS.

Currently it seems the only reasonable choices are

  • - for cs-general clients
  • - for cs-teaching clients

Hosts using such configuration do not necessarily need to be strictly in the same region as the named "relayhost", as long as the relayhost is configured to accept it.

Beware the following lines which might get put in the file by default, but which will cause harm. Remove or comment them out.

default_transport = error
relay_transport = error

Note also that setting the following to non-empty

mydestination = 

will result in an attempt to locally deliver mail for the given list of hostnames, which is not wanted if we have only the "smart" "mailhub" machines set up with procmail, spamassassin, general forwarding capability, etc.

In the recent past many machines were observed to be left with the following configuration which I think is installed by default.

inet_interfaces = all

That causes a server to appear on port 25 (SMTP). It appears the resulting Postfix server will never allow open relaying (which is a good thing), but it could annoy people doing security checks, and confuse other people.


smtp_connection_cache_on_demand = yes
smtp_connection_cache_destinations = $relayhost
smtp_connection_cache_time_limit = 60s
relayhost =

While previously postfix versions might be encountered which would not run if given the above configuration, that no longer seems to be the case. However, it actually seems now that, in newer versions, something equivalent to the above is done as/by the default configuration. Although an attempt to formally verify that is not convincing, empirically clients without the above do not seem to have the tendency to get items stuck in the local mailq waiting for relaying.


Useful message under construction.



We have been assuming /etc/mailname contains the appropriate "domain" name. That should be ensured, so that mail appears to originate from a reasonably appropriate domain, and not an actual hostname of expected temporary existence (for instance, using the actual FQDN of the machine being configured is usually a bad idea).

-- AdrianPepper - 2013-10-08 -- Adrian Pepper - 2020-12-07

Edit | Attach | Watch | Print version | History: r12 < r11 < r10 < r9 < r8 | Backlinks | Raw View | WYSIWYG | More topic actions
Topic revision: r12 - 2020-12-08 - AdrianPepper
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2021 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback