Skip to content

Relay Hosts


Rather than having Postfix deliver mail directly, you can configure Postfix to send mail via another mail relay (smarthost). Examples include Mailgun, Sendgrid and AWS SES.

Depending on the domain of the sender, you may want to send via a different relay, or authenticate in a different way.

Basic Configuration

Basic configuration is done via environment variables:

  • RELAY_HOST: default host to relay mail through, empty (aka '', or no ENV set) will disable this feature
  • RELAY_PORT: port on default relay, defaults to port 25
  • RELAY_USER: username for the default relay
  • RELAY_PASSWORD: password for the default user

Setting these environment variables will cause mail for all sender domains to be routed via the specified host, authenticating with the user/password combination.


For users of the previous AWS_SES_* variables: please update your configuration to use these new variables, no other configuration is required.

Advanced Configuration

Sender-dependent Authentication

Sender dependent authentication is done in docker-data/dms/config/ You can create this file manually, or use: relay add-auth <domain> <username> [<password>]

An example configuration file looks like this:           relay_user_1:password_1           relay_user_2:password_2

If there is no other configuration, this will cause Postfix to deliver email through the relay specified in RELAY_HOST env variable, authenticating as relay_user_1 when sent from and authenticating as relay_user_2 when sending from


To activate the configuration you must either restart the container, or you can also trigger an update by modifying a mail account.

Sender-dependent Relay Host

Sender dependent relay hosts are configured in docker-data/dms/config/ You can create this file manually, or use: relay add-domain <domain> <host> [<port>]

An example configuration file looks like this:        []:587        []:2525

Combined with the previous configuration in docker-data/dms/config/, this will cause Postfix to deliver mail sent from via, authenticating as relay_user_1, and mail sent from via authenticating as relay_user_2.


You still have to define RELAY_HOST to activate the feature

Excluding Sender Domains

If you want mail sent from some domains to be delivered directly, you can exclude them from being delivered via the default relay by adding them to docker-data/dms/config/ with no destination. You can also do this via: relay exclude-domain <domain>

Extending the configuration file from above:        []:587        []:2525

This will cause email sent from to be delivered directly.