Translation(s): English - Português (Brasil)

How to send mail with Exim through an SSH tunnel

A. Start the ssh tunnel

ssh $HOST -L 2525:$MSERVER:25

(where $HOST is the host you're tunneling through and $MSERVER is the outbound SMTP server you want to use)

B. Configure exim

1. Add a new transport file /etc/exim4/conf.d/transport/40_tunneled_smtp :

  #################################
  # This transport is used for delivering messages over SSH-tunneled SMTP
  # connections to port 2525 on localhost

  ssh_tunneled_smtp:
    debug_print = "T: tunneled remote_smtp for $local_part@$domain"
    driver = smtp
    allow_localhost = true
    port = 2525
    hosts = 127.0.0.1
    hosts_override = true

2. Edit /etc/exim4/conf.d/router/200_exim4-config_primary. In the 'smarthost:' section, change

      transport = remote_smtp_smarthost

to

      transport = ssh_tunneled_smtp

3. /etc/init.d/exim4 reload

Some variations

   transport = ${lookup{transport}lsearch{/etc/roaming/exim_options}{$value}{remote_smtp_smarthost}}

then, /etc/roaming/exim_options could contain:

   transport: ssh_tunneled_smtp

or nothing at all to use the default

1. Add a new file /etc/exim4/conf.d/main/04_roaming :

  # If the file /etc/roaming/not_online exists, don't send the messages but
  # enqueue them only
  queue_only_file = /etc/roaming/not_online

2. Add ifupdown hooks to create and remove the file:

  iface home inet static
    [...]
    up echo '' > /etc/roaming/exim_options
    up rm -f /etc/roaming/not_online

  iface work inet static
    [...]
    up echo 'transport: ssh_tunneled_smtp' > /etc/roaming/exim_options
    up touch /etc/roaming/not_online


Enrico Zini


CategoryNetwork CategorySoftware CategoryMail