I've been thinking for a while about a setup I would like to achieve, and I still have some questions about it. What I'm trying to build is basically a Postfix server which checks the received mail against a MySQL database and checks what to do next with the email.
The MySQL database would contain the following tables: - domain -> Contains all domains we relay mail for, as well as their next destination, either send elsewhere by SMTP (smtp:[mail.example.com]) or deliver locally (local) -> Also contains whether or not mail sent to this domain needs to be checked for UCE - alias -> Contains origin & destination addresses (ex: [email protected] -> [email protected]) -> Also contains whether or not mail sent to this alias needs to be checked for UCE - user -> Contains local mailbox information: address, username, password, ... -> Also contains whether or not mail sent to this alias needs to be checked for UCE Basically, the flow I want is the following: -> mail ([email protected]) ?? do we relay for example.com? [lookup in domain table] -> yes ?? do we relay locally or SMTP? [lookup in domain table] -> locally ?? does the to: email address exist? [lookup in user and alias table] -> yes ?? is UCE filtering enabled for this email address/whole domain? [lookup in user and alias table] -> yes ++ send to filter server -> no ++ send to delivery server -> no ++ bounce -> SMTP ?? is UCE filtering enabled for the domain? [lookup in domain table] -> yes ++ send to filter server -> no ++ send by smtp to "transport"-field -> no ++ bounce This would serve a few features: - If no UCE-filtering is required, the UCE-filter server will never have to care about the message (less load) - We could serve as a relay for certain domains and redirect them to a "hidden mail exchanger", possibly hidden behind a dynamic IP (updated in our database) or non-standard port on another network. - We could serve as a UCE-filter for certain domains, filter the UCE and pass the email on to another "hidden mail exchanger" (see previous point) But I'm not entirely sure how to make this logic work. Does anyone have a pointer towards a similar configuration? Any other hints? Could I, for example, run a script when Postfix receives a mail at SMTP time and that tells Postfix what to do with the message? Ideally, this should all be possible with two databases max, I guess. I think I have all the ingredients, but I'm lacking the recipe. I'm not very familiar with Postfix, so please forgive me any stupid questions I might ask. :)
