I've got postfix setup so that mail coming in from smtpd is automatically filtered through spamassassin (which reinjects it into the mailqueue with added headers)

Now I want to do 2 things with messages that are considered spam:

  1. If the mail is outbound again (because of aliases) discard the mail on the spot
  2. If the mail is for a local virtual user hand it off to Dovecot which puts it in the Spam folder.

Can I configure postfix this way? All my alias and user information are in MySQL. Currently I discard all spam mail (with a header_checks in main.cf) but I would prefer the above situation.

  • great question. the first point would be very useful.
    – hayalci
    Jul 13, 2009 at 13:36

1 Answer 1


You could setup another smtp listener process in your master.cf to handle your outgoing mail. Something like the following should get you started with one listening on port 26:

26        inet  n       -       n       -       18       smtpd -o header_checks=[your checks] mydestination= relayhost=

You may need to tweak that slightly, to disable local delivery and not to accept mail from anywhere except localhost. You'd then want to add the following to your main.cf


And of course, drop your header checks out of that file.

Mail out would be relayed into the second smtpd process on 26 which would then drop messages that fail as spam. You can also specify a relayhost in that listener if you need pass your mail to a downstream server rather than delivering directly.

You'd then go about setting up the rest of your filtering for your local users with Dovecot like you'd already suggested.

You will of course want to consdier how many mail hops you add to your message when doing this as some mail providers will drop messages with a considerable number of hops (gmail for instance drops after something like 10 or 15

  • genuine msh technology!
    – Zanchey
    Jul 15, 2009 at 13:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .