Relay Mail From Localhost Using Postfix


On a system on which we do not wish to have local mail, we need to relay locally-generated (system) mail to another host. This article discusses how to set that up.


  • We assume the System MTA is Postfix.


  1. Configure /etc/aliases

    1. Add a line with root: (with the desired destination mail of course) to /etc/aliases
    2. Execute newaliases
  2. Configure /etc/postfix/canonical

    1. Create /etc/postfix/canonical with contents such as the following, where is the host’s hostname, is your mail domain, and is the domain of the recipient (which may be your domain: in this example):
    1. Execute postmap hash:/etc/postfix/canonical
  3. Configure /etc/postfix/

    1. Set myorigin = $mydomain
    2. Set mydestination = (this tells the system we don’t accept any mail as local).
    3. Set recipient_canonical_maps = hash:/etc/postfix/canonical
    4. Set inet_interfaces = localhost
    5. Set mynetworks_style = host
    6. Set relay_domains = (obviously should be yourdomain.tld)
  4. Restart postfix

  5. Test sending mail from your localhost to various addresses (especially ones related to your domain and your localhost) and make sure the results are what you expect.

End Note

If you need to authenticate to your mail relay to send mail (e.g. if you are not only sending mail to yourself), then you will need to configure SASL as usual. Otherwise, it really is that easy!.