exim 4 : add header to ALL messages

Solution 1:

I've recently had the same challenge, and after much searching didn't find anything. This is my solution which does seem to work, but is specific to my setup, so, check how your exim is actually delivering mail.

We are using a Smarthost (Mailgun) and Exim is configured via the GUI. This can generate the split config files as you have seen. Note you could ask Exim to consolidate the files here, but we're using other software which also modifies the standard Exim config, and so we need the split method.

I then manually edited /etc/exim4/conf.d/transport/30_exim4-config_remote_smtp_smarthost, which I believe is the actual transport used when sending outgoing mail via a smarthost. This is what my version looks like now:

remote_smtp_smarthost:
  debug_print = "T: remote_smtp_smarthost for $local_part@$domain"
  driver = smtp
  headers_add = "X-Mailgun-Drop-Message: true"
  hosts_try_auth = <; ${if exists{CONFDIR/passwd.client} \
        {\
        ${lookup{$host}nwildlsearch{CONFDIR/passwd.client}{$host_address}}\
        }\
        {} \
      }
.ifdef REMOTE_SMTP_SMARTHOST_HOSTS_AVOID_TLS
  hosts_avoid_tls = REMOTE_SMTP_SMARTHOST_HOSTS_AVOID_TLS
.endif
.ifdef REMOTE_SMTP_HEADERS_REWRITE
  headers_rewrite = REMOTE_SMTP_HEADERS_REWRITE
.endif
.ifdef REMOTE_SMTP_RETURN_PATH
  return_path = REMOTE_SMTP_RETURN_PATH
.endif
.ifdef REMOTE_SMTP_HELO_DATA
  helo_data=REMOTE_SMTP_HELO_DATA
.endif
.ifdef TLS_DH_MIN_BITS
tls_dh_min_bits = TLS_DH_MIN_BITS
.endif

I added the headers_add parameter at line 4 - this is a test server, so I want Mailgun to drop all outbound mail, and this is the way to do it via SMTP.

What I'm not 100% certain of is how robust this is to updates and reconfiguration. I'm about to post a related question about that, and will link to this one.