How to set up Email Redirects properly

Your question

I’ve read several topics regarding email redirects, and my conclusion is that this is the best way to forward incoming emails from Stalwart to Gmail.

Without keeping a local Stalwart copy:

require ["redirect", "variables", "envelope"];
set "envelope.from" "[email protected]";
redirect "[email protected]";

Keeping a local Stalwart copy:

require ["copy", "redirect", "variables", "envelope"];
set "envelope.from" "[email protected]";
redirect :copy "[email protected]";

No DKIM/SPF changes should be necessary.

Could you please let me know if the above information is correct?

Thank you!

Both scripts work, but the set “envelope.from” lines do nothing. A user’s script can’t change the envelope; the line compiles and is ignored. You don’t need it: a redirect from a user’s script always goes out with that account’s own address as the return path, so Gmail checks SPF against your domain and any bounce comes back to the user, not to the original sender. Stalwart also DKIM-signs the redirected copy with your domain by default. So no extra DKIM or SPF work is needed, as long as your domain’s SPF covers the server and DKIM is set up, which your own outgoing mail needs anyway. With :copy the minimum is:

require ["copy"];
redirect :copy "[email protected]";

Without :copy nothing stays in the Stalwart mailbox. What you can’t control is DMARC at Gmail. It’s checked against the From header, which is the original sender’s domain, so a forwarded message only passes if the sender’s own DKIM signature survives the trip. Stalwart doesn’t rewrite senders with SRS and doesn’t ARC-seal, so mail from p=reject domains without an intact signature can be rejected or land in spam. Forwarding spam also costs your domain reputation with Gmail, so I’d leave out what the filter marked as spam:

require ["copy", "spamtest", "relational", "comparator-i;ascii-numeric"];
if not spamtest :value "eq" :comparator "i;ascii-numeric" "10" {
    redirect :copy "[email protected]";
}

Amazing, as always! Thank you!