• We value your experience with Plesk during 2026
    Please help us understand which Plesk features made your work easier this year, what is still missing and how AI should help you in Plesk ?
    Take this short 5-minutes survey. Your answers go straight into the Plesk roadmap for 2027.

Question How to prepend [EXT] to external emails (Postfix/SpamAssassin/Sieve)

tessa67

Regular Pleskian
Server operating system version
Debian 11
Plesk version and microupdate number
18.0.80 #3
Hello everyone,

using the configuration specified in my signature, I would like to prepand an "[EXT]" to the subject line of external emails, or write "EXTERNAL" at the very beginning of the email body.

All my attempts using header_checks, SpamAssassin, and Sieve have failed so far, and I am starting to wonder if this is even possible with my setup.

The domains examplea.com, exampleb.com, and examplec.com are internal email domains. Emails between these domains should remain untouched.
 
Sieve should be the right tools for this. You'll need some additional Dovecot configuration if you want the subject to be changed server wide for all mailboxes. If you want this just for one (or a couple) mailboxes than you can just apply a Sieve filter script for those specific mailboxes mailboxes. Roundcube for example let's you modify filter rules for a specific mailbox.

Sieve filter example script:
Code:
require ["editheader", "variables", "envelope"];

if allof (
    envelope :domain :is "to"
        ["examplea.com", "exampleb.com", "examplec.com"],

    not address :domain :is "From"
        ["examplea.com", "exampleb.com", "examplec.com"],

    not header :matches "Subject" "[EXT]*"
) {
    if header :matches "Subject" "*" {
        set "original_subject" "${1}";

        deleteheader "Subject";
        addheader "Subject" "[EXT] ${original_subject}";
    }
    else {
        # Handle messages without a Subject header.
        addheader "Subject" "[EXT]";
    }
}
* I've not tested this Sieve filter script, test first and use with caution.
 
Thank you very much! It works with sieve.

/etc/dovecot/sieve.d/10-external-tag.sieve
Code:
require ["editheader", "variables", "regex"];

if not header :regex "From" "@(examplea\.com|exampleb\.com|examplec\.com)" {

    if not header :contains "Subject" "[EXT]" {

        if header :matches "Subject" "*" {
            deleteheader "Subject";
            addheader :last "Subject" "[EXT] ${1}";
        }
    }
}

/etc/dovecot/conf.d/95-custom-sieve.conf
Code:
sieve_extensions {
  editheader = yes
  variables = yes
}

sieve_script custom_before {
  path = /etc/dovecot/sieve.d/10-external-tag.sieve
  type = before
}
 
However, your code is faster, more efficient, and more secure. Regex can be quite slow... ;)
 
Back
Top