728x90
반응형

Postfix + header_checks in MySQL

 
In this tip I will describe how to implement Postfix header_checks along with MySQL . No blablabla....let's get straight to the point. For everything to work it is necessary to have MySQL installed. On Debian like distributions, type the following command to install the MySQL server: # apt-get install mysql-server-5.5 After that, follow the installation steps that will be described on the screen. Log in as ROOT in your MySQL and create the database "postfix", or any other name that is easy to identify: # mysql -u root -p CREATE DATABASE postfix; Enter the postfix database to be able to create the table inside it: use postfix;

Now create the header_checks table with the following command:

CREATE TABLE `header_checks` (
  `hc_id` int(11) NOT NULL AUTO_INCREMENT,
  `rule` varchar(255) NOT NULL,
  `action` varchar(255) NOT NULL,
  PRIMARY KEY ( `hc_id`),
  KEY `rule` (`rule`)
) ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=utf8

Postfix preparation

I believe that you must already have Postfix installed on your server, there are already several articles dealing with its installation.

We will now create the configuration file for communicating with MySQL:

# vi /etc/postfix/header_checks.cf

Put this content inside the file we are editing:
user = YOUR_BANK_USER_postfix
password = YOUR_BANK_PASSWORD_postfix
hosts = IP_or_YOUR_Server_NAME
dbname = DATABASE_NAME_postfix
query = SELECT action FROM header_checks WHERE '%s' REGEXP rule LIMIT 0.1
Next step is to edit the configuration in the /etc/postfix/main.cf file , if you don't already have the line below, add it:
header_checks = mysql:/etc/postfix/header_checks.cf
With these steps completed, we just have to restart postfix and populate the header_checks table in MySQL, which I will show the correct syntax below.

# /etc/init.d/postfix restart

Creating check rules in MySQL

Here we don't have many secrets, what gave me more work was finding the correct syntax to write the rule, but I'll save you this hard work and pass the correct syntax the way I'm using it on my servers.

Access MYSQL:

# mysql -u root -p

use postfix;

INSERT INTO header_checks (`hc_id`, `rule`, `action`) VALUES (NULL, '^From:(.*)domain.com.br', 'DISCARD #SPAM Domain Detected');


Note that the syntax for REGEXP used by header_checks follows the following pattern:

^From:(.*)dominio.com.br

I particularly use this rule to block domains that usually send SPAMs, but we can use it, for example, to block messages with certain subjects, in this case the rule would look like this:

^Subject:(.*)PROPAGANDA

Well folks, that's it...

I hope the subject has been addressed in a clear and objective way.

Hugs.

Measure
Measure
 
 
728x90
SMALL
Posted by gromet

블로그 이미지
나는 운이 좋은 사람이다 나는 나날이 점점 더 좋아진다 내가 하는 선택과 행동은 반드시 성공으로 이어진다 내게는 인내력과 지속력이 있다 네게는 좋은것들만 모여든다
gromet

공지사항

Yesterday
Today
Total
반응형

달력

 « |  » 2024.9
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30

최근에 올라온 글

최근에 달린 댓글

최근에 받은 트랙백

글 보관함

160x600