install Postfix

Install Postfix

postfix-centosPostfix est un agent de transfert de courrier (MTA) open-source très répandu qui peut être utilisé pour router et envoyer des emails sur un système Linux. On estime qu’environ 25% des serveurs de messagerie publics sur Internet exécutent Postfix.

Dans ce guide, nous allons vous apprendre comment démarrer rapidement avec Postfix sur un serveur Linux.

Afin de configurer correctement Postfix, vous aurez besoin d’un nom de domaine complet pointé vers votre serveur Linux. Si vous envisagez d’accepter le courrier, vous devez vous assurer que vous avez également un enregistrement MX pointant vers votre serveur de messagerie.

Trouver version postfix avec postconf 

# postconf -d | grep mail_version

postfix

Voir la queue de postfix :

# postqueue –p

Vider la queue postfix :

# postqueue –f

Supprimer un courriel postfix dans la queue :

# postsuper -d ID

qshape incoming active deferred

# postsuper -d all

Purger les mail postfix en attente avec perl:

# perl -e 'foreach (`postqueue -p`) {`postsuper -d $1` if /^([0-9A-Z]+)/}'

Script permettant de purger les mail en attente de postfix :

#!/usr/bin/perl

‘foreach (`postqueue -p`) {`postsuper -d $1` if /^([0-9A-Z]+)/}’

 

Vérifier les alias postfix sur nom@domaine.com dans MySQL :

 

# mysql -p

Login mysql

# select * from alias where address like 'nom@domaine.com';
# update alias set goto = 'nom@domaine.com, nom2@domaine.com' where address = 'nom@domaine.com';

Revenir à la normale postfix :

# update alias set goto = 'nom@domaine.com' where address = 'nom@domaine.com';

Installation Postfix avec MySql

Debian

# apt-get install postfix-mysql

# mysqladmin -u root create postfix
# GRANT SELECT, INSERT, DELETE, UPDATE ON postfix.* TO postfix@localhost;
# GRANT USAGE ON postfix.* TO postfix@localhost;

Relay :
relayhost = 192.168.0.180

Créez la table d’alias postfix mysql :

USE postfix; CREATE TABLE `alias` ( `address` varchar(255) NOT NULL default '', `goto` text NOT NULL, `domain` varchar(255) NOT NULL default '', `created` datetime NOT NULL default '0000-00-00 00:00:00', `modified` datetime NOT NULL default '0000-00-00 00:00:00', `active` tinyint(1) NOT NULL default '1', PRIMARY KEY  (address) ) TYPE=MyISAM COMMENT='Postfix Admin - Virtual Aliases';

Créez la table de domaine postfix mysql :

USE postfix; CREATE TABLE `domain` ( `domain` varchar(255) NOT NULL default '', `description` varchar(255) NOT NULL default '', `aliases` int(10) NOT NULL default '0', `mailboxes` int(10) NOT NULL default '0', `maxquota` int(10) NOT NULL default '0', `transport` varchar(255) default NULL, `backupmx` tinyint(1) NOT NULL default '0', `created` datetime NOT NULL default '0000-00-00 00:00:00', `modified` datetime NOT NULL default '0000-00-00 00:00:00', `active` tinyint(1) NOT NULL default '1', PRIMARY KEY  (domain) ) TYPE=MyISAM COMMENT='Postfix Admin - Virtual Domains';

 

Créez la table Mailbox postfix mysql :

USE postfix; CREATE TABLE `mailbox` ( `username` varchar(255) NOT NULL default '', `password` varchar(255) NOT NULL default '', `name` varchar(255) NOT NULL default '', `maildir` varchar(255) NOT NULL default '', `quota` int(10) NOT NULL default '0', `domain` varchar(255) NOT NULL default '', `created` datetime NOT NULL default '0000-00-00 00:00:00', `modified` datetime NOT NULL default '0000-00-00 00:00:00', `active` tinyint(1) NOT NULL default '1', PRIMARY KEY  (`username`) ) TYPE=MyISAM COMMENT='Postfix Admin - Virtual Mailboxes';

Remplir les tables postfix mysql :

 USE postfix; INSERT INTO domain (domain,description) VALUES ('domain.tld','Test Domain'); INSERT INTO alias (address,goto) VALUES ('alias@domain.tld', 'user@domain.tld'); INSERT INTO mailbox (username,password,name,maildir)  VALUES ('user@domain.tld','$1$caea3837$gPafod/Do/8Jj5M9HehhM.','Mailbox User','user@domain.tld/')
USE postfix; INSERT INTO domain (domain,description) VALUES ('domaine.com','Titre Doamine'); INSERT INTO alias (address,goto) VALUES ('admins@domaine.com', 'user@domaine.com'); INSERT INTO mailbox (username,password,name,maildir)  VALUES ('user@domaine.com','password','user','user@domaine.com/');
# mkdir /usr/local/virtual
# chown -R postfix.postfix /usr/local/virtual
# chmod -R 771 /usr/local/virtual
mysql_virtual_alias_maps.cf
 You will need to put this into a text file for postfix to pickup.
 user = postfix
 password = postfix
 hosts = localhost
 dbname = postfix
 table = alias
 select_field = goto
 where_field = address

Syntaxe avec postfix 2.2.x :

user = postfix
password = postfix
hosts = localhost
dbname = postfix
query = SELECT goto FROM alias WHERE address='%s' AND active = 1
mysql_virtual_domains_maps.cf
 You will need to put this into a text file for postfix to pickup.
 user = postfix
 password = postfix
 hosts = localhost
 dbname = postfix
 table = domain
 select_field = domain
 where_field = domain
 #additional_conditions = and backupmx = '0' and active = '1'

Syntax with postfix 2.2.x:

user = postfix
 password = postfix
 hosts = localhost
 dbname = postfix
 query = SELECT domain FROM domain WHERE domain='%s'
 #optional query to use when relaying for backup MX
 #query = SELECT domain FROM domain WHERE domain='%s' and backupmx = '0' and active = '1'mysql_virtual_mailbox_maps.c

Vous aurez besoin de mettre cela dans un fichier texte pour postfix pickup :

user = postfix
 password = postfix
 hosts = localhost
 dbname = postfix
 table = mailbox
 select_field = maildir
 where_field = username
 #additional_conditions = and active = '1'

Syntax with postfix 2.2.x :

 user = postfix
 password = postfix
 hosts = localhost
 dbname = postfix
 query = SELECT maildir FROM mailbox WHERE username='%s' AND active = 1
# vi main.cf
command_directory = /usr/sbin
daemon_directory = /usr/lib/postfix
program_directory = /usr/lib/postfix
smtpd_banner = $myhostname ESMTP $mail_name (Debian/GNU)
setgid_group = postdrop
biff = no
allow_percent_hack = no
swap_bangpath      = no

Ajout .domaine dans le MIA’s job :

 append_dot_mydomain = yes
myhostname = newsletter.domaine.com
 alias_maps = hash:/etc/aliases,hash:/var/lib/mailman/data/aliases
 alias_database = hash:/etc/aliases
 mydomain = domaine.com
 myorigin = news.domaine.com
#myorigin = $myhostname
 #inet_interfaces = $myhostname, 192.168.80.52, localhost
 inet_interfaces = all

# La liste des machines/domaines que l’on considère local :

mydestination = localhost.localdomain, localhost, newsletter
 #relayhost =
 mynetworks = 127.0.0.0/8, 192.168.0.0/24, 192.168.6.0/24
mailbox_command = procmail -a "$EXTENSION"

#Mail delivery should be tried only once

La distribution du courrier devrait être essayé qu’une seule fois :

 bounce_queue_lifetime = 0
cal_destination_concurrency_limit = 2
 initial_destination_concurrency = 5
 default_destination_concurrency_limit = 20
 smtp_connect_timeout = 10
 smtp_helo_timeout = 10
 notify_classes = 2bounce, resource, software

Comment doit-il résoudre les adresses local :

local_recipient_maps = $alias_maps unix:passwd.byname
 alias_maps = hash:/etc/aliases
 alias_database = hash:/etc/aliases
#mailbox_command =
 mailbox_size_limit = 0
 recipient_delimiter = +
 #soft_bounce = yes
 #transport_maps=hash:/etc/postfix/transport
 readme_directory = no
 sample_directory = /etc/postfix
 sendmail_path = /usr/sbin/sendmail
 html_directory = no
 manpage_directory = /usr/local/man
 newaliases_path = /usr/bin/newaliases
 mailq_path = /usr/bin/mailq
 queue_directory = /var/spool/postfix
 mail_owner = postfix
 unknown_local_recipient_reject_code = 450
 owner_request_special = no

Boite Virtuel :

 virtual_mailbox_base = /usr/local/virtual
 virtual_mailbox_domains = mysql:/etc/postfix/mysql_virtual_domains_maps.cf
 virtual_mailbox_maps = mysql:/etc/postfix/mysql_virtual_mailbox_maps.cf
 virtual_mailbox_limit = 51200000
 virtual_minimum_uid = 100
 virtual_transport = virtual
 virtual_alias_maps = mysql:/etc/postfix/mysql_virtual_alias_maps.cf
 virtual_gid_maps = static:106
 virtual_uid_maps = static:105
# vi master.cf
smtp      inet  n       -       n       -       20      smtpd -v -o content_filter=filter:
 #smtp      inet  n       -       n       -       20      smtpd
 #submission inet n      -       -       -       -       smtpd
 #       -o smtpd_etrn_restrictions=reject
 #628      inet  n       -       -       -       -       qmqpd
 pickup    fifo  n       -       n       60      1       pickup
 cleanup   unix  n       -       n       -       0       cleanup
 qmgr      fifo  n       -       n       300     1       qmgr
 #qmgr     fifo  n       -       -       300     1       oqmgr
 rewrite   unix  -       -       n       -       -       trivial-rewrite
 bounce    unix  -       -       n       -       0       bounce
 defer     unix  -       -       n       -       0       bounce
 trace     unix  -       -       -       -       0       bounce
 verify    unix  -       -       -       -       1       verify
 flush     unix  n       -       -       1000?   0       flush
 proxymap  unix  -       -       n       -       -       proxymap
 smtp      unix  -       -       n       -       -       smtp
 relay     unix  -       -       -       -       -       smtp
 #       -o smtp_helo_timeout=5 -o smtp_connect_timeout=5
 showq     unix  n       -       -       -       -       showq
 error     unix  -       -       -       -       -       error
 local     unix  -       n       n       -       -       local
 virtual   unix  -       n       n       -       -       virtual
 lmtp      unix  -       -       n       -       -       lmtp
 anvil     unix  -       -       n       -       1       anvil
maildrop  unix  -       n       n       -       -       pipe
 flags=DRhu user=vmail argv=/usr/local/bin/maildrop -d ${recipient}
 uucp      unix  -       n       n       -       -       pipe
 flags=Fqhu user=uucp argv=uux -r -n -z -a$sender - $nexthop!rmail ($recipient)
 ifmail    unix  -       n       n       -       -       pipe
 flags=F user=ftn argv=/usr/lib/ifmail/ifmail -r $nexthop ($recipient)
 bsmtp     unix  -       n       n       -       -       pipe
 flags=Fq. user=bsmtp argv=/usr/lib/bsmtp/bsmtp -d -t$nexthop -f$sender $recipient
 scalemail-backend unix  -       n       n       -       2       pipe
 flags=R user=scalemail argv=/usr/lib/scalemail/bin/scalemail-store ${nexthop} ${user} ${extension}
 filter    unix  -       n       n       -       -       pipe user=filter argv=/var/spool/filter/mfy.sh -f ${sender} -- ${reci
 pient}

Installation courier–pop postfix :

# apt-get install courier-pop courier-authmysql courier-imap courier-authdaemon courier-authmysql remplacer par courier-authlib-mysql

courier-authlib-userdb

# apt-get install courier-authlib-mysql

Supprimer le skip-networking dans my.cnf MySQL :

# vi authdaemonrc :
authmodulelist="authmysql"
# vi authmysqlrc :
MYSQL_SERVER    127.0.0.1
 MYSQL_USERNAME  postfix
 MYSQL_PASSWORD  postfix
 MYSQL_SOCKET    /var/run/mysqld/mysqld.sock
 MYSQL_PORT      3306
 MYSQL_DATABASE  postfix
 MYSQL_USER_TABLE        mailbox
 MYSQL_CRYPT_PWFIELD     password
 MYSQL_UID_FIELD 104
 MYSQL_GID_FIELD 105
 MYSQL_LOGIN_FIELD       username
 MYSQL_HOME_FIELD        '/usr/local/virtual'
 MYSQL_NAME_FIELD        name
 MYSQL_MAILDIR_FIELD     maildir

Postfixadmin :

# apt-get install php5-mysql

Laisser un commentaire

Votre adresse de messagerie ne sera pas publiée.

* Copy This Password *

* Type Or Paste Password Here *