Instalar y Confiurar Postfix en Debian Lenny
1. Instalar Postfix y SASL
apt-get install postfix postfix-mysql libsasl2-modules-sql sasl2-bin libsasl2-2 postfix-tls libpam-mysql > Internet Site > host.domain.com2. Crear la base de datos y las tablas (mysql -u root -p)
# Crear la base da datos llamada mail
CREATE DATABASE mail;# Crear un usuario y le damos permisos para manejar la base de datos
GRANT SELECT ON mail.* TO ‘{username}’@’localhost’ IDENTIFIED BY ‘{password}’;FLUSH PRIVILEGES;
# Seleccionamos la base
USE mail;# Creamos la tabla que contiene los dominios que manejara este servidor
CREATE TABLE domains ( domain varchar(255) NOT NULL, PRIMARY KEY (domain) ) TYPE=MyISAM;# Creamos la tabla de forwards de las direcciones de e-mail
CREATE TABLE forwardings ( source varchar(255) NOT NULL, destination varchar(255) NOT NULL, PRIMARY KEY (source) ) TYPE=MyISAM;# Creamos la tabla de correos / usuarios
CREATE TABLE users ( email varchar(255) NOT NULL, password varchar(255) NOT NULL, quota int(10) DEFAULT ‘104857600’, PRIMARY KEY (email) ) TYPE=MyISAM;# Creamos la tabla llamada transport
CREATE TABLE transport ( domain varchar(255) NOT NULL, transport varchar(255) NOT NULL, UNIQUE KEY domain (domain) ) TYPE=MyISAM;{username} = Es el usuario de MySQL que creamos
{password} = Es el password del usuario de MySQL que creamos
3. Creamos los mapeos entre Postfix y MySQL
Domains (nano /etc/postfix/mysql-virtual_domains.cf)
user = {username} password = {password} dbname = mail table = domains select_field = ‘virtual’ where_field = domain hosts = 127.0.0.1Forwards (nano /etc/postfix/mysql-virtual_forwardings.cf)
user = {username} password = {password} dbname = mail table = forwardings select_field = destination where_field = source hosts = 127.0.0.1Mailboxes / Users (nano /etc/postfix/mysql-virtual_mailboxes.cf)
user = {username} password = {password} dbname = mail table = users select_field = CONCAT(SUBSTRING_INDEX(email,’@’,-1),’/’,SUBSTRING_INDEX(email,’@’,1),’/’) where_field = email hosts = 127.0.0.1E-mail to E-mail (nano /etc/postfix/mysql-virtual_email2email.cf)
user = {username} password = {password} dbname = mail table = users select_field = email where_field = email hosts = 127.0.0.1Transports (nano /etc/postfix/mysql-virtual_transports.cf)
user = {username} password = {password} dbname = mail table = transport select_field = transport where_field = domain hosts = 127.0.0.1Quota (nano /etc/postfix/mysql-virtual_mailbox_limit_maps.cf)
user = {username} password = {password} dbname = mail table = users select_field = quota where_field = email hosts = 127.0.0.1Destinations (nano /etc/postfix/mysql-mydestination.cf)
user = {username} password = {password} dbname = mail table = transport select_field = domain where_field = domain hosts = 127.0.0.1{username} = Es el usuario de MySQL que creamos
{password} = Es el password del usuario de MySQL que creamos
4. Cambiamos permisos a los nuevos archivos
chmod 640 /etc/postfix/mysql-*.cf chgrp postfix /etc/postfix/mysql-*.cf5. Cramos un usuario local y grupo para los usuarios virtuales
groupadd -g 5000 vmail useradd -g vmail -u 5000 vmail -d /home/vmail -m6. Creamos el certificado para TLS
openssl req -new -outform PEM -out /etc/postfix/smtpd.cert -newkey rsa:2048 -nodes -keyout /etc/postfix/smtpd.key -keyform PEM -days 3650 -x509 chmod 640 /etc/postfix/smtpd.key7. Configuramos Postfix, hay ejecutar cada linea desde consola
postconf -e ‘mydestination = localhost, proxy:mysql:/etc/postfix/mysql-mydestination.cf’ postconf -e ‘virtual_alias_maps = proxy:mysql:/etc/postfix/mysql-virtual_forwardings.cf, mysql:/etc/postfix/mysql-virtual_email2email.cf’ postconf -e ‘virtual_mailbox_domains = proxy:mysql:/etc/postfix/mysql-virtual_domains.cf’ postconf -e ‘virtual_mailbox_maps = proxy:mysql:/etc/postfix/mysql-virtual_mailboxes.cf’ postconf -e ‘virtual_mailbox_base = /home/vmail’ postconf -e ‘virtual_uid_maps = static:5000’ postconf -e ‘virtual_gid_maps = static:5000’ postconf -e ‘smtpd_sasl_auth_enable = yes’ postconf -e ‘smtpd_helo_required = yes’ postconf -e ‘broken_sasl_auth_clients = yes’ postconf -e ‘smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination’ postconf -e ‘smtpd_use_tls = yes’ postconf -e ‘smtpd_tls_cert_file = /etc/postfix/smtpd.cert’ postconf -e ‘smtpd_tls_key_file = /etc/postfix/smtpd.key’ postconf -e ‘strict_rfc821_envelopes = yes’ postconf -e ‘disable_vrfy_command = yes’ postconf -e ‘transport_maps = proxy:mysql:/etc/postfix/mysql-virtual_transports.cf’ postconf -e ‘virtual_create_maildirsize = yes’ postconf -e ‘virtual_mailbox_extended = yes’ postconf -e ‘virtual_mailbox_limit_maps = proxy:mysql:/etc/postfix/mysql-virtual_mailbox_limit_maps.cf’ postconf -e ‘virtual_mailbox_limit_override = yes’ postconf -e ‘virtual_maildir_limit_message = «Account is over quota»‘ postconf -e ‘virtual_overquota_bounce = yes’ postconf -e ‘proxy_read_maps = $local_recipient_maps $mydestination $virtual_alias_maps $virtual_alias_domains $virtual_mailbox_maps $virtual_mailbox_domains $relay_recipient_maps $relay_domains $canonical_maps $sender_canonical_maps $recipient_canonical_maps $relocated_maps $transport_maps $mynetworks $virtual_mailbox_limit_maps’8. Habilitamos los puertos seguros: 465 y 587 (nano /etc/postfix/master.cf)
smtps inet n – – – – smtpd -o smtpd_tls_wrappermode=yes -o smtpd_sasl_auth_enable=yes -o smtpd_client_restrictions=permit_sasl_authenticated,reject -o milter_macro_daemon_name=ORIGINATING 587 inet n – – – – smtpd -o smtpd_tls_wrappermode=yes -o smtpd_sasl_auth_enable=yes -o smtpd_client_restrictions=permit_sasl_authenticated,reject -o milter_macro_daemon_name=ORIGINATINGConfiguramos SASL para la autenticación SMTP
9. Creamos el folder para el archivo SASL PID
mkdir -p /var/spool/postfix/var/run/saslauthd10. Habilitamos SASL (nano /etc/default/saslauthd)
START=yes OPTIONS=»-c -m /var/spool/postfix/var/run/saslauthd -r»11. Configuramos SASL para usar la nueva ruta del PID file (nano /etc/init.d/saslauthd)
PIDFILE=»/var/spool/postfix/var/run/${NAME}/saslauthd.pid»12. Configuramos PAM para usar MySql para la autenticacion (nano /etc/pam.d/smtp)
auth required pam_mysql.so user={username} passwd={password} host=127.0.0.1 db=mail table=users usercolumn=email passwdcolumn=password crypt=1 account sufficient pam_mysql.so user={username} passwd={password} host=127.0.0.1 db=mail table=users usercolumn=email passwdcolumn=password crypt=1{username} = Es el usuario de MySQL que creamos
{password} = Es el password del usuario de MySQL que creamos
13. Configuramos Postfix para usar SASl para la autenticaión SMTP (nano /etc/postfix/sasl/smtpd.conf)
pwcheck_method: saslauthd mech_list: plain login allow_plaintext: true auxprop_plugin: mysql sql_hostnames: 127.0.0.1 sql_user: {username} sql_passwd: {password} sql_database: mail sql_select: select password from users where email = ‘%u’{username} = Es el usuario de MySQL que creamos
{password} = Es el password del usuario de MySQL que creamos
14. Reiniciamos Postfix y SASL
/etc/init.d/saslauthd restart /etc/init.d/postfix restartAhora trabajaremos los datos de la tabla
1. Damos de alta el dominio que manejara nuestros correos.
INSERT INTO domains VALUES (‘domain.com’);2. Creamos el usuario/buzon.
INSERT INTO users VALUES (‘user@domain.com’, ENCRYPT(‘password’), 104857600);3. Creamos los forwards. Este forward es de un email llegue a otro o a varios emails
INSERT INTO forwardings VALUES (‘user2@domain.com’, ‘user@domain.com’);Hacer un Forward a multiples correos usando comas para separarlas
INSERT INTO forwardings VALUES (‘user3@domain.com’, ‘user@domain.com,user@gmail.com’);4. Forward de todos los correos de un dominio a otro servidor de correo
INSERT INTO transport VALUES (‘domain.com’, ‘smtp:server2.domain.com’);