7

I run a Postfix server with Amavis and Spamassassin among other things. Postfix receives mail from the outside world and passes it on to Amavis. Amavis has Spamassassin rate the mail, and then tags it as spam if necessary. Then Postfix relies on each users' procmailrcs to deal with the mail as they will. I believe this is the correct approach because I believe each user should have the ability to choose what to do with their spam. Unfortunately, we also have some users with foregin domains in our virtual alises list. Because these addresses don't have user accounts with our servers, the spam that is forwarded to them is never put through a procmailrc and we end up forwarding spam, already tagged as spam, to other servers. Is there a way to stop outgoing mail already tagged as spam? Or is there any other way to fix this?

EDIT: I only wish to delete the messages that are both spam AND being forwarded to other servers. I don't want to delete all mails marked as spam. Is there a way to distinguish between the two?

1 Answers1

2

You can delete emails with a particular tag in header.

See Postfix Header Checks Man page for details.

Example:

In "/etc/postfix/main.cf", add

header_checks = regexp:/etc/postfix/header_checks

In "/etc/postfix/header_checks", have

/^(Subject: \[SPAM\])(.+)$/ DISCARD

The above will discard all emails whose Subject starts with "[SPAM]".

EDIT: I only wish to delete the messages that are both spam AND being forwarded to other servers. I don't want to delete all mails marked as spam. Is there a way to distinguish between the two?

This could be done by running two instances within Postfix. The first instance will forward the email to second instance (instead of to Remote email server). The same can be achieved by specifying a local transport.

The second instance will have the above header_checks. This way only emails to remote server will have their SPAM deleted.

Some references:

  1. Specifying Transport
  2. You can run multiple instances of Postfix by specifying additional entries in master.cf file. Details here