2

I'm looking for a way to add headers to all outgoing emails in exim4 (debian 8 setup).

I have tried differents things based on headers_add but i guess my main question is where to put this rule (the config is split in many files in conf.d).

The online documentation of exim isn't so clear to me about that point.

Regards

webofmars
  • 180
  • 7

1 Answers1

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.

dsl101
  • 433
  • 1
  • 7
  • 13
  • I did eventually find a router-based solution which I included in my question here - this might suit you better than editing the Smarthost transport: http://serverfault.com/questions/770269/minimal-exim-router-which-simply-adds-custom-header – dsl101 Apr 14 '16 at 09:51