2

I answered this question with my current solution, but as I said I'm not 100% happy with it. That solution to the question 'How to add a custom header to all outgoing mail' involved adding the headers_add parameter into the existing Smarthost transport. However, I can see updates or reconfiguration reverting my edit at some point without me knowing.

I had hoped to create a minimal router which would run early on in the chain and just add the required header - this header can be added to all mail, whether it ends up being for local or remote delivery. But I couldn't find any example of a router which runs, adds the header then passes all messages on to the next router in the chain. I created this, which seems to work, but I'm very new to Exim and would be grateful if anyone can point out flaws or a better way to achieve the desired outcome. The router is /etc/exim4/conf.d/router/01_exim4-config_dev_header:

dev_header:
    debug_print = "R: dev_header for $local_part@$domain"
    driver = redirect
    headers_add = "X-Test-Dev-Header: true"
    data = $local_part@$domain
    self = pass

bumped to the homepage by Community 2 days ago

This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.

0

You don't need a router to do this. It is much more easier (and, in my opinion, cleaner) to have a statement in the acl_smtp_data ACL, which does nothing but adds the header, like this:

warn add_header = X-Test-Dev-Header: true

See "Adding header lines in ACLs" for more info.

How to enable this rule

I'm assuming you have the "split" configuration.

  1. Look for a file named main/0000-localmacros or similar. If it doesn't exist, create it.
  2. The file should contain a line like this:

    CHECK_DATA_LOCAL_ACL_FILE=/etc/exim4/some/file
    

    If it doesn't, add this line. The filename can be anything.

  3. Write the line above into the /etc/exim4/some/file file (the warn add_header... one).
  4. Reconfigure exim. On Debian this is done by running the dpkg-reconfigure exim4-config command.

After this, every mail should contain the header you specified.

  • I read that documentation as only being able to add headers to received mail, not sent mail - "The add_header modifier is permitted in the MAIL, RCPT, PREDATA, DATA, MIME, DKIM, and non-SMTP ACLs (in other words, those that are concerned with receiving a message)." Or am I misunderstanding what 'receiving' means here? – dsl101 May 27 '16 at 13:06
  • I just create a file called 10_exim4-config_devmail with this content: acl_smtp_data: warn add_header = X-Test-Dev-Header: true and while exim didn't reject the new configuration, the header doesn't appear in outgoing mail... – dsl101 May 27 '16 at 13:13
  • Yes, you misunderstood. From exim's viewpoint "receiving" a message is the process of getting a message through the network. It is irrelevant what will happen with the message. If you use exim as a smarthost, it will "receive" your message, and "send" it afterwards if the address isn't a local one. The documentation says you can add headers while receiving a message, but not when you're about to send it out. – Lacek May 27 '16 at 13:25
  • I've edited my answer to contain instructions on how to enable the rule in exim. – Lacek May 27 '16 at 13:32
  • Thanks for the detailed instructions. I am trying to add this header to mail generated locally for remove delivery via a smarthost, and I'm pretty sure I followed - I have split config, and there was no 0000-localmacros in /var/exim4/conf.d/main so I created it with contents CHECK_DATA_LOCAL_ACL_FILE=/etc/exim4/dev.headers and /etc/exim4/dev.headers contains warn add_header = X-Test-Dev-Header: true. I then ran dpkg-reconfigure exim4-config, accepting all existing values. Exim restarted, no console warnings, but still no headers. – dsl101 May 27 '16 at 14:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.