LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Server (https://www.linuxquestions.org/questions/linux-server-73/)
-   -   Postfix mail filter (https://www.linuxquestions.org/questions/linux-server-73/postfix-mail-filter-906334/)

Emil M 10-04-2011 04:36 AM

[SOLVED] Postfix mail filter
 
I have a Debian server with Postfix and would like to know if it's possible to create some "manual" filters, move/reject mails if the body contains something, if the header does and if it's sent to a specific person etc? Maybe coupling it with mysql

TB0ne 10-04-2011 08:50 AM

Quote:

Originally Posted by Emil M (Post 4489553)
I have a Debian server with Postfix and would like to know if it's possible to create some "manual" filters, move/reject mails if the body contains something, if the header does and if it's sent to a specific person etc? Maybe coupling it with mysql

Since you're using Postfix, you should look into spamassasin.
http://spamassassin.apache.org/

Configs for it are in plain text, so it should be easy to put in whatever rule(s) you're looking for, and disable the ones you don't want.

Emil M 10-04-2011 09:23 AM

I can see that this might fit my needs
http://svn.apache.org/repos/asf/spam...3.3/sql/README


Do you know how to enable spamassassin for Postfix and to check if it's working properly?

TB0ne 10-04-2011 09:30 AM

Quote:

Originally Posted by Emil M (Post 4489752)
I can see that this might fit my needs
http://svn.apache.org/repos/asf/spam...3.3/sql/README

Do you know how to enable spamassassin for Postfix and to check if it's working properly?

There are many how-tos you can find on Google. Some are even linked from the Postfix website:
http://www.postfix.org/docs.html
http://www.akadia.com/services/postf...massassin.html

Emil M 10-05-2011 03:20 AM

Thanks. I've configured Spamassassin now (without MySQL for now), but I'm facing some issues which restricts me from sending and receiving mails:


Code:

Oct  5 10:15:39 *** postfix/smtpd[20357]: fatal: open database /etc/postfix/access_client.db: No such file or directory
Oct  5 10:15:40 *** postfix/master[20259]: warning: process /usr/lib/postfix/smtpd pid 20357 exit status 1
Oct  5 10:15:40 *** postfix/master[20259]: warning: /usr/lib/postfix/smtpd: bad command startup -- throttling

I tried to follow this:
http://www.debuntu.org/postfix-and-p...filter-spam-p2

Emil M 10-05-2011 03:55 AM

Solved!

I had this in my main.cf

Code:

smtpd_recipient_restrictions =
    permit_mynetworks,
    permit_sasl_authenticated,
    reject_unauth_destination,
    reject_invalid_hostname,
    reject_unauth_pipelining,
    reject_non_fqdn_sender,
    reject_unknown_sender_domain,
    reject_non_fqdn_recipient,
    reject_unknown_recipient_domain,
    check_client_access hash:$config_directory/access_client,
    check_sender_access hash:$config_directory/access_sender
    permit

worked when i removed the last 3 lines

Emil M 10-05-2011 04:47 AM

It looks like it doesn't look up for the right account, and just uses spamd system user?

Code:

Oct  5 11:45:50.601 [21443] dbg: config: Conf::SQL: executing SQL: select preference, value from userpref where username = 'spamd' or username = '@GLOBAL' order by username asc

to start spamd i use
Code:

-q -x -u spamd -D

-- That's for sure the problem! It works when I use @GLOBAL or spamd as account, how do I combine these rules with virtual SQL users?



Maybe user should be ${recipient} in postfix? My conclusion: No!

Code:

postfix  21541 20259  0 11:58 ?        00:00:00 pipe -n spamassassin -t unix user=spamd argv=/usr/bin/spamc -f -e /usr/sbin/sendmail -oi -f ${sender} ${recipient}
root    21557    1  1 11:58 ?        00:00:01 /usr/sbin/spamd -d -m5 -x -q -Q -u nobody
nobody  21558 21557  0 11:58 ?        00:00:00 spamd child
nobody  21559 21557  0 11:58 ?        00:00:00 spamd child
root    21577 21268  0 12:00 pts/1    00:00:00 grep spamd


Emil M 10-05-2011 05:19 AM

I've read that I should use a custom query for my purpose in /etc/spamassassin/local.cf, so I used this one as the documentation said, but without any luck:

Code:

user_scores_sql_custom_query    SELECT preference, value FROM _TABLE_ WHERE username = _USERNAME_ OR username = '@GLOBAL' ORDER BY username ASC
It works with @GLOBAL, but accounts doesn't.

Emil M 10-05-2011 05:56 AM

Got it !

http://serversupportforum.de/forum/m...elle-user.html

In /etc/postfix/master.cf

argv=/usr/bin/spamc -u ${recipient}

It's important to have -u ${recipient}


Thanks for the links to get started, TB0ne. Hope someone some day can use my thoughts here.

TB0ne 10-05-2011 10:06 AM

Quote:

Originally Posted by Emil M (Post 4490458)
Got it !

http://serversupportforum.de/forum/m...elle-user.html

In /etc/postfix/master.cf

argv=/usr/bin/spamc -u ${recipient}

It's important to have -u ${recipient}
Thanks for the links to get started, TB0ne. Hope someone some day can use my thoughts here.

No problems..glad it helped. And thanks to your following up on what you've done and how, you've already helped quite a few folks with the same issue/question.


All times are GMT -5. The time now is 07:03 AM.