0

I need to make a filter for outgoing mail. To copy messages if "to" contains the given e-mail address.I have:

# rule:[Copy to slack]
if address :contains "to" "test@example.com"
{
    redirect :copy "XXXXXXXXXX@example.slack.com";
}

and i try

# rule:[Copy to slack]
if address :contains "to" "test@example.com"
{
    redirect :copy "test2@example.com";
}

or

# rule:[Copy to ]
if address :contains "to" "test@example.com"
{
      fileinto "INBOX.Redmine";
}

But every time the filter doesn't work.

This only works if I'm sending from the address I have in "to" or other local mail.

Any ideas?

onev
  • 1
  • 1
  • 2
    Sieve is integrated into Dovecot to be triggered during *final delivery* of mail, or by actions via IMAP - not for submission. Please [edit] your question to clarify the context in which your script is meant to be executed. Typically, submitted mail would not involve Dovecot except for a copy being optionally stored in the Sent folder. – anx Sep 10 '21 at 15:21
  • In this case "to" is external email, example gmail.com – onev Sep 10 '21 at 15:35
  • For local mailboxes - works properly. – onev Sep 10 '21 at 15:40
  • 1
    it works properly for local mailboxes because it's an incoming mail for Dovecot. Dovecot does not send mails, your MTA does. – Gerald Schneider Sep 10 '21 at 16:09

1 Answers1

1

It does not work because it cannot work this way: If you are sending mail, you are sending it to port 465 directly to Postfix - no Sieve script will be executed.

If you want to use the sieve language to work on outgoing mail, you would have to put in much more effort, because it is not nicely integrated into common software, at least nowhere near as nice as the Pigeonhole Sieve integration in Dovecot which will only trigger in two specific use cases:

  1. on receiving mail, a.k.a the final delivery stage of mail destined for a mailbox Dovecot manages, or
  2. on managing a mailbox, specifically actions of a local or IMAP-connected client on a mailbox Dovecot manages.

Notable, that integration will not handle the case of mail submission: While Dovecot does include a submission proxy, it is generally not involved at all in that direction, and in rare cases where this is used, then still not handling Sieve.

You got a few options now:

  • trigger your script on the mail that is stored to a "sent" mailbox (but that would not act on mail that is not stored in that mailbox)
  • replace your script with built-in functionality of Postfix. recipient_bcc_maps comes to mind
  • configure postfix header_checks to simply reject mail that does not follow your policy (e.g. skips over the desired To: header, then reject all incomplete versions of it)
  • configure the copy in some milter/filter
  • configure an (preferably new, local) address which you setup to be expanded to the two addresses you want to receive the mail, let users send their mail there
  • pipe mail for that recipient to a script, possibly one using your Sieve script (unlikely your best shot: using sieve outside of the LDA use case is simply not well supported by any existing software)
anx
  • 6,875
  • 4
  • 22
  • 45
  • i try recipient_bcc_maps (the exim equivalent) but this only works for sender addresses (I need specific recipients) (and not forward just a copy). ```copy_from_skrzynka: driver = redirect condition = ${if eq{$sender_address}{skrzynka@example.org}{yes}{no}} data = inna_skrzynka@domena.pl unseen``` But I don't see a global function for the recipient. I'm thinking about the script. Only how can I send copies from the .Sent directory to the chosen e-mail address – onev Sep 14 '21 at 19:43
  • Odd that you mention *Exim*, but your question is tagged *Postfix*. What is the MTA that you submit to? – anx Sep 14 '21 at 19:47
  • 1
    Sorry, I gave the wrong tag. Exim. – onev Sep 14 '21 at 20:03