Exim filter to act on all outgoing emails
Hello,
I look for some direction.
I wish to remove some headers from all outgoing emails.
I have a good code for finding and removing the headers.
I wish to avoid a cumbersome code to check all the headers of to, cc and bcc for all the email domains I have today on CP and negate it (which can also be added in the future with more domains and I will forget to add them to this filter...) - as the condition/trigger to do it on all outgoing emails.
Is there a way to define all outgoing emails by their target relay smart hosts (I need to match a list of CIDR networks)?
It looks more elegant and future-proof to me.
Thanks!
-
OK, I managed to solve it with a custom exim filter, in a rather good way, not the best, not future proof, but OK for start with. Directions I tried and didn't work so far: 1. Looking outbound - I first tried to look at it from the recipients perspective, so first I tried to use the exim $domain variable (the domain part of an email address, whatever is to the right of the @ sign), as it applies to the fields of to, cc and bcc all together, but it looks like it also applies to the sender email, so it was not good, too wide 2. The best way is to remove the headers only at the last step of exim, right before it sends the email to the external smart host, but for this I needed to change the exim config, which cannot be done directly, but rather via the "side" file of exim.conf.local, but I didn't find a way how to do it. The relevant part at the main config file was the router section of "literal" Disadvantages of the currently used filter: 1. It will remove headers also if the email is sent to recipients of the same domain as of the sender or other domains managed by the same cPanel exim (any domains mentioned in the script). Some will find this an advantage, if they wish to remove the headers no-matter-what 2. If domains are add/changed/removed - the admin need to remember to update the filter accordingly, or the filter will not act upon them Advantages of the currently used filter and explaining my choices: 1. While recipients can be many, to, cc and bcc, the sender is only and always - just one, so I used the exim variable of $sender_address, which is the email's envelope "from" header, not of the email client app/script, but the one the exim server is using, hence it is not relying on anything the client did/played-with See here for more info about this variable - x-originating-ip The IP address from which the email delivery started, the IP of the email client that initiated the delivery, many times it is an internal IP address inside the network 0 -
Some suggestions/request for cPanel, following my time with writing and testing this exim custom filter file: Background 1. When I edited the file I had some issues with the file editor, so Linux saved an additional, temp file, at the same folder, with an extension of .save. The problem is that the "exim configuration manager" (at least as the UI representation of things), constantly reads the custom filters folder, /usr/local/cpanel/etc/exim/sysfilter/options/, and automatically adds any files there to the list of custom filters and add the in an "On" mode, which is the default status for custom filter files, so each file is automatically processed, even if the admin is not aware of the addition of this system backup file... 2. If an exim custom filter is not valid - it cause emails to get stuck in the mail queue and adds an error record line to exim's panic log, at /var/log/exim_paniclog So, I suggest (and of course, if you change it, publicly post about them): 1. Change the default mode of exim custom filter files to be "Off", it is safer this way 2. Consider adding custom filter files to the exim processing only if they are using a certain extension or, instead, don't run files ending with certain extensions, like .save. This will help to better verify only file wished to be run - will run 3. If a custom filter file caused an error to exim - change its operational mode to "Off" and add a marking extension to it, like .error. Consider adding adding a log record for this event and an alert delivery of email to the admin. This will help preventing invalid custom filters from blocking the whole mail queue 0 -
Thanks for sharing the workaround you found! I usually don't comment on Exim filter issues because it's not something we directly support on our end. Could you submit those three ideas as official feature requests? 0
Please sign in to leave a comment.
Comments
4 comments