Mailcow: Global Filter for Forwarding

Modified on Thu, 26 Mar at 1:02 PM

Set this as the Global Prefilter to do forwards for all maiboxes.


Password Reset Codes

subject:Your request to reset password OR subject:SeatGeek password

forward to: ***@lab.ticketattendant.com

deliver to: codes@(domain).com

DON'T deliver to: (domain)@(domain).com


Authentication Codes

subject:Authentication Code OR subject:Sign into your account OR subject:Verify your identity

deliver to: codes@(domain).com

DON'T deliver to: (domain)@(domain).com


Purchases

subject:You Got Tickets OR subject:Your tickets are available on SeatGeek

forward to: ***@lab.ticketattendant.com

deliver to: purchases@**externaldomain**.com GMAIL

deliver to: (domain)@(domain).com


Everything for each domain (except the codes above):

deliver to: (domain)@(domain).com



## new Global Prefilter
## append before the default filter, overwriting the original require line

require ["fileinto", "copy", "variables", "envelope", "subaddress", "mailbox"];

# Extract the parts of the incoming email address.
if envelope :matches "to" "*@*.*" {
    set "localpart" "${1}";
    set "domainname" "${2}";
    set "tld" "${3}";
}

# ---------------------------------------------------------
# 0. Sieve Loop & Duplicate Prevention
# ---------------------------------------------------------
# If this header exists, it means our script already processed this email 
# on the catchall mailbox, and routed it here.
# We just need to keep it in the current mailbox and stop.
if exists "X-Sieve-Redirected-From" {
    keep;
    stop;
}

# ---------------------------------------------------------
# 1. Password Reset Codes
# ---------------------------------------------------------
if header :contains "Subject" ["Your request to reset password", "SeatGeek password"] {
    # ALWAYS send to Ticket Attendant on the "First Touch"
    redirect :copy "***@lab.ticketattendant.com";
    redirect :copy "codes@**masterdomain**.com";
    
    # If someone emailed codes@ directly, just keep it here.
    if string :is "${localpart}" "codes" {
        keep;
    } else {
        # Otherwise, it hit the catchall, so route it to codes@.
        redirect "codes@${domainname}.${tld}";
    }
    stop;
}

# ---------------------------------------------------------
# 2. Authentication Codes
# ---------------------------------------------------------
elsif header :contains "Subject" ["Authentication Code", "Sign into your account", "Verify your identity"] {
    if string :is "${localpart}" "codes" {
        keep;
    } else {
        redirect "codes@${domainname}.${tld}";
    }
    stop;
}

# ---------------------------------------------------------
# 3. Purchases
# ---------------------------------------------------------
elsif header :contains "Subject" ["You Got Tickets", "Your tickets are available on SeatGeek"] {
    redirect :copy "***@lab.ticketattendant.com";
    redirect :copy "purchases@**externaldomain**.com";
    keep; # Ensures it STILL delivers to the original mailbox
    stop;
}

# ---------------------------------------------------------
# 4. Everything Else
# ---------------------------------------------------------
# You don't actually need to write a rule for the default action! 
# Sieve's default behavior is to deliver the email to the original destination 
# if no previous rules hit a "discard" or "stop" command.

Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select at least one of the reasons
CAPTCHA verification is required.

Feedback sent

We appreciate your effort and will try to fix the article