Email > Forward to (only when not SPAM)?

When I add an email adress in the “Forward to (one or more email addresses)” field in hestia it doesn’t matter if HestiaCP/SpamAssassin detects an incoming email as spam or not - it gets forwarded to that email adress.

Can I change that so only messages with spam score below my set level (50) gets forwarded at all?

I think I’ve got it by adding the following condition to the aliases: section in /etc/exim4/exim4.conf.template

aliases:
  driver = redirect
  headers_add = X-redirected: yes
  data = ${extract{1}{:}{${lookup{$local_part@$domain}lsearch{/etc/exim4/domains/${lookup{$domain}dsearch{/etc/exim4/domains/}}/aliases}}}}
  require_files = /etc/exim4/domains/$domain/aliases
  redirect_router = dnslookup
  pipe_transport = address_pipe
  unseen
  condition = ${if !match{$h_X-Spam-Status:}{\N^Yes\N}{true}{false}}
1 Like

I looked into the current default debian exim4.conf.template file (/usr/local/hestia/install/deb/exim/exim4.conf.template) and there the data line looked different.

I have

data = ${extract{1}{:}{${lookup{$local_part@$domain}lsearch{/etc/exim4/domains/${lookup{$domain}dsearch{/etc/exim4/domains/}}/aliases}}}}

in /usr/local/hestia/install/deb/exim/exim4.conf.template it is

data = ${extract{1}{:}{${lookup{$local_part@$domain}lsearch{/etc/exim4/domains/$domain/aliases}}}}

I thought I change it also in my used file to the new format but exim mainlog showed those errors after that:

 Tainted filename for search: '/etc/exim4/domains/mydomain.de/aliases'
2025-03-13 23:05:33 H=mail-ua1-f41.google.com [209.85.222.41] X=TLS1.3:ECDHE_SECP256R1__RSA_PSS_RSAE_SHA256__AES_256_GCM:256 CV=no SNI=mail.mydomain.de F=<[email protected]> temporarily rejected RCPT <[email protected]>: 
failed to expand "${extract{1}{:}{${lookup{$local_part@$domain}lsearch{/etc/exim4/domains/$domain/aliases}}}}": NULL

(so I had to switch back to my old working version)