Skip to content

Sending outbound email through remote mail server

To set up outbound email sending through remote mail server, fill in example values and copy generated snippets to their respective files. If Remote mail server requires custom port, it could be added by appending ::PORT to the hostname (e.g. mail.example.com::587)

Remote server hostname:

Authentication User:

Authentication Password:

/etc/exim.authenticators.post.conf

auth_login:
    driver = plaintext
    public_name = LOGIN
    hide client_send = : [[INSERT USERNAME HERE]] : [[INSERT PASSWORD HERE]]

/etc/exim.transports.pre.conf

auth_relay:
    driver = smtp
    port = 25
    message_linelength_limit = 52428800
    hosts_require_auth = *
    hosts_require_tls = *
    headers_add = "${if def:authenticated_id{X-Authenticated-Id: ${authenticated_id}}}"
    interface = <; ${if exists{/etc/virtual/domainips}{${lookup{$sender_address_domain}lsearch*{/etc/virtual/domainips}}}}
    helo_data = ${if exists{/etc/virtual/helo_data}{${lookup{$sending_ip_address}iplsearch{/etc/virtual/helo_data}{$value}{$primary_hostname}}}{$primary_hostname}}
    hosts_try_chunking =
    hosts_try_fastopen =
.include_if_exists /etc/exim.dkim.conf

auth_relay_forward:
    driver = smtp
    port = 25
    message_linelength_limit = 52428800
    hosts_require_auth = *
    hosts_require_tls = *
    headers_add = "${if def:authenticated_id{X-Authenticated-Id: ${authenticated_id}}}"
    interface = <; ${if exists{/etc/virtual/domainips}{${lookup{$sender_address_domain}lsearch*{/etc/virtual/domainips}}}}
    helo_data = ${if exists{/etc/virtual/helo_data}{${lookup{$sending_ip_address}iplsearch{/etc/virtual/helo_data}{$value}{$primary_hostname}}}{$primary_hostname}}
    hosts_try_chunking =
    hosts_try_fastopen =
    max_rcpt = 1
    return_path = ${srs_encode {SRS_SECRET} {$return_path} {$original_domain}}
.include_if_exists /etc/exim.dkim.conf

/etc/exim.routers.pre.conf

smart_route:
    driver = manualroute
    ignore_target_hosts = 127.0.0.0/8
    condition = ${if or { \
                    {bool{FORCED_MX_DNS_CHECK}} \
                    {!match_domain{$domain}{+local_domains}} \
                }}
    transport = ${if eq{$domain}{$original_domain} \
                    {auth_relay} \
                    {auth_relay_forward} \
                }
    self = pass
    route_list = * smtp.example.com
    no_more

Sending outbound email through remote mail server without authetnication

To set up outbound email sending through remote mail server that does not require user authentication, fill in example values and copy generated snippets to their respective files. If Remote mail server requires custom port, it could be added by appending ::PORT to the hostname (e.g. mail.example.com::587)

Remote server hostname:

/etc/exim.routers.pre.conf

smart_route:
    driver = manualroute
    ignore_target_hosts = 127.0.0.0/8
    condition = ${if or { \
                    {bool{FORCED_MX_DNS_CHECK}} \
                    {!match_domain{$domain}{+local_domains}} \
                }}
    transport = ${if eq{$domain}{$original_domain} \
                    {remote_smtp} \
                    {remote_smtp_forward_transport} \
                }
    self = pass
    route_list = * smtp.example.com
    no_more

For changes to take effect, exim will need to be restarted using

bash
systemctl restart exim