En este post vamos a configurar un sistema de correo en Debian 7 compuesto por Postfix, Dovecot, Amavis (con Spamassassin + ClamAV) y PostfixAdmin para un dominio tal que dominio.tld. ¿Qué es qué?
Al lio:
/etc/hostname: nombredelhost.dominio.tld apt-get install apache2 libapache2-mod-php5 php5-imap php5-mysql mysql-server mysql-client postfixadmin $CONF['configured'] = true; $CONF['setup_password'] = '1c286753554c26d26ec8baad09795715:2f818806f8917160537e5ccb0588a274460ed491'; $CONF['postfix_admin_url'] = 'http://dominio.tld/postfixadmin'; $CONF['default_language'] = 'es'; $CONF['database_type'] = 'mysqli'; $CONF['database_host'] = 'localhost'; $CONF['database_user'] = 'postfixadmin'; $CONF['database_password'] = 'postfixadmin'; $CONF['database_name'] = 'postfixadmin'; $CONF['default_aliases'] = array ( 'abuse' => 'abuse@dominio.tld', 'postmaster' => 'postmaster@dominio.tld' ); $CONF['encrypt'] = 'cleartext'; $CONF['domain_path'] = 'YES'; $CONF['domain_in_mailbox'] = 'NO'; $CONF['quota'] = 'YES'; $CONF['transport'] = 'NO'; $CONF['transport_options'] = array ( 'virtual', // for virtual accounts 'local', // for system accounts 'relay', // for backup mx 'dovecot' ); $CONF['transport_default'] = 'dovecot'; $CONF['vacation'] = 'NO'; $CONF['alias_control'] = 'YES'; $CONF['alias_control_admin'] = 'YES'; $CONF['emailcheck_resolve_domain']= 'NO'; $CONF['create_mailbox_subdirs']=array("Sent","Junk","Draft","Trash"); $CONF['create_mailbox_subdirs_host']='localhost'; $CONF['used_quotas'] = 'YES'; apt-get install amavisd-new spamassassin clamav-daemon /etc/default/spamassassin: ENABLED=1 CRON=1 /etc/init.d/spamassassin restart adduser clamav amavis /etc/init.d/clamav-daemon restart /etc/amavis/conf.d/15-content_filter_mode: # Descomentamos las siguientes lineas: @bypass_virus_checks_maps = ( \%bypass_virus_checks, \@bypass_virus_checks_acl, \$bypass_virus_checks_re); @bypass_spam_checks_maps = ( \%bypass_spam_checks, \@bypass_spam_checks_acl, \$bypass_spam_checks_re); /etc/amavis/conf.d/20-debian_defaults: # Tuneamos el puntaje de Spamassassin y siempre añadimos los X-Spam headers: #$sa_spam_subject_tag = '***SPAM*** '; # No queremos modificar los originales! $sa_tag_level_deflt = -999; # Siempre añadimos los spam info headers $sa_tag2_level_deflt = 4; # Añadimos los 'spam detected' headers $sa_kill_level_deflt = 10; # Envio de correo DSN... $sa_dsn_cutoff_level = 10; # ...que no se enviará nunca. Hará quarantine (en /var/lib/amavis/virusmails/) /etc/amavis/conf.d/05-domain_id: ###chomp($mydomain = `head -n 1 /etc/mailname`); $mydomain = 'dominio.tld'; /etc/init.d/amavis restart # TIP (oda a find): Cómo buscar mails en el directorio de cuarentena por defecto... find /var/lib/amavis/virusmails/ -type f #... consultarlos rápidamente (sólo si hay pocos!)... find /var/lib/amavis/virusmails/ -type f -exec zless {} \; #... y si ninguno nos convence, borrarlos: find /var/lib/amavis/virusmails/ -type f -exec rm -f {} \; apt-get install postfix postfix-mysql smtpd_banner = $myhostname ESMTP $mail_name (Debian/GNU) biff = no append_dot_mydomain = no myorigin = $myhostname mydestination = $myhostname, localhost.localdomain, localhost mynetworks = 127.0.0.0/8 mailbox_size_limit = 0 recipient_delimiter = + inet_interfaces = all inet_protocols = ipv4 smtpd_delay_reject = no smtpd_helo_required = yes # Restrictions applied in the context of a client connection request. smtpd_client_restrictions = permit_mynetworks, permit_sasl_authenticated, #reject_unknown_client_hostname, #reject_unknown_reverse_client_hostname, reject_rbl_client sbl-xbl.spamhaus.org, reject_rbl_client bl.spamcop.net # Restrictions applied in the context of a client HELO command. smtpd_helo_restrictions = permit_mynetworks, reject_invalid_helo_hostname, reject_non_fqdn_helo_hostname # Restrictions applied in the context of a client MAIL FROM command. smtpd_sender_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_non_fqdn_sender # Restrictions applied in the context of a client RCPT TO command. smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_non_fqdn_recipient, reject_unknown_recipient_domain, reject_unauth_destination, permit message_size_limit = 26214400 receive_override_options = no_address_mappings default_process_limit = 10 smtp_connect_timeout = 20s smtp_helo_timeout = 20s smtpd_timeout = 30s smtpd_junk_command_limit = 10 # Configuraciones mapeadas a MySQL virtual_mailbox_domains = proxy:mysql:/etc/postfix/mysql_virtual_domains_maps.cf virtual_mailbox_maps = proxy:mysql:/etc/postfix/mysql_virtual_mailbox_maps.cf virtual_alias_maps = proxy:mysql:/etc/postfix/mysql_virtual_alias_maps.cf transport_maps = proxy:mysql:/etc/postfix/mysql_virtual_transport_maps.cf relay_domains = proxy:mysql:/etc/postfix/mysql_virtual_relay_domains_maps.cf # Hacemos que Postfix autentique con Dovecot broken_sasl_auth_clients = yes smtpd_sasl_type = dovecot smtpd_sasl_path = private/auth smtpd_sasl_auth_enable = yes smtpd_sasl_local_domain = $myhostname smtpd_sasl_security_options = noanonymous # Amavis como filtro de contenidos en su default port content_filter = smtp-amavis:[127.0.0.1]:10024 # TLS (también conocido como "el nuevo SSL") smtp_use_tls = yes smtpd_use_tls = yes smtp_tls_note_starttls_offer = yes smtpd_tls_cert_file=/etc/dovecot/dovecot.pem smtpd_tls_key_file=/etc/dovecot/private/dovecot.pem # Dovecot LDA (para que sea dovecot quien haga el delivery de los correos) dovecot unix - n n - - pipe flags=DRhu user=vmail:vmail argv=/usr/lib/dovecot/deliver -d ${recipient} # El filtro amavis con el puerto por defecto (10024) smtp-amavis unix - - - - 2 smtp -o smtp_data_done_timeout=1200 -o smtp_send_xforward_command=yes # El reinjection path por defecto de amavis (10025) 127.0.0.1:10025 inet n - - - - smtpd -o content_filter= -o local_recipient_maps= -o relay_recipient_maps= -o smtpd_restriction_classes= -o smtpd_delay_reject=no -o smtpd_client_restrictions=permit_mynetworks,reject -o smtpd_helo_restrictions= -o smtpd_sender_restrictions= -o smtpd_recipient_restrictions=permit_mynetworks,reject -o mynetworks_style=host -o mynetworks=127.0.0.0/8 -o strict_rfc821_envelopes=yes -o smtpd_error_sleep_time=0 -o smtpd_soft_error_limit=1001 -o smtpd_hard_error_limit=1000 -o smtpd_client_connection_count_limit=0 -o smtpd_client_connection_rate_limit=0 -o receive_override_options=no_header_body_checks,no_unknown_recipient_checks /etc/postfix/mysql_virtual_alias_maps.cf: user = postfixadmin password = postfixadmin hosts = localhost dbname = postfixadmin table = alias select_field = goto where_field = address /etc/postfix/mysql_virtual_domains_maps.cf: user = postfixadmin password = postfixadmin hosts = localhost dbname = postfixadmin table = domain select_field = domain where_field = domain additional_conditions = and backupmx = '0' and active = '1' /etc/postfix/mysql_virtual_mailbox_limit_maps.cf: user = postfixadmin password = postfixadmin hosts = localhost dbname = postfixadmin table = mailbox select_field = quota where_field = username additional_conditions = and active = '1' /etc/postfix/mysql_virtual_mailbox_maps.cf: user = postfixadmin password = postfixadmin hosts = localhost dbname = postfixadmin table = mailbox select_field = maildir where_field = username /etc/postfix/mysql_virtual_relay_domains_maps.cf: user = postfixadmin password = postfixadmin hosts = localhost dbname = postfixadmin table = domain select_field = domain where_field = domain additional_conditions = and backupmx = '1' /etc/postfix/mysql_virtual_transport_maps.cf: user = postfixadmin password = postfixadmin hosts = localhost dbname = postfixadmin table = domain select_field = transport where_field = domain additional_conditions = and active = '1' apt-get install dovecot-imapd dovecot-mysql dovecot-sieve /etc/dovecot/dovecot.conf: # Sólo queremos ipv4 listen = * # Procesos de sistema más "verbosos" verbose_proctitle = yes /etc/dovecot/conf.d/10-auth.conf: disable_plaintext_auth = no auth_mechanisms = plain login !include auth-sql.conf.ext /etc/dovecot/conf.d/10-logging.conf: log_timestamp = "%Y-%m-%d %H:%M:%S " deliver_log_format = msgid=%m: %$ : Subject: %s /etc/dovecot/conf.d/10-mail.conf: mail_privileged_group = mail /etc/dovecot/conf.d/10-master.conf: service auth { unix_listener auth-userdb { mode = 0660 user = vmail group = vmail } # Postfix smtp-auth unix_listener /var/spool/postfix/private/auth { mode = 0660 user = postfix group = mail } } service imap-login { inet_listener imap { #port = 143 } inet_listener imaps { # Deshabilitar el puerto 993 porque usaremos STARTTLS: # http://www.dovecot.org/list/dovecot/2010-March/047479.html port = 0 #port = 993 #ssl = yes } } /etc/dovecot/conf.d/10-ssl.conf: ssl = yes ssl_cert = </etc/dovecot/dovecot.pem ssl_key = </etc/dovecot/private/dovecot.pem ssl_cipher_list = ALL:!LOW:!SSLv2:!EXP:!aNULL /etc/dovecot/conf.d/15-lda.conf: postmaster_address = postmaster@dominio.tld protocol lda { mail_plugins = quota sieve } /etc/dovecot/conf.d/20-imap.conf: protocol imap { mail_plugins = quota imap_quota } /etc/dovecot/conf.d/auth-sql.conf.ext: passdb { driver = sql args = /etc/dovecot/dovecot-sql.conf.ext } userdb { driver = sql args = /etc/dovecot/dovecot-sql.conf.ext } /etc/dovecot/conf.d/90-quota.conf: plugin { quota = dict:user::proxy::quota } dict { quota = mysql:/etc/dovecot/dovecot-dict-sql.conf.ext } driver = mysql connect = host=localhost dbname=postfixadmin user=postfixadmin password=postfixadmin default_pass_scheme = PLAIN user_query = \ SELECT CONCAT('/home/mail/', maildir) AS home, \ CONCAT('maildir:/home/mail/', maildir,'Maildir') AS mail, \ 500 AS uid, 500 AS gid, \ CONCAT('*:bytes=', CAST(quota AS CHAR)) AS quota_rule \ FROM mailbox WHERE username = '%u' AND active = '1' password_query = \ SELECT username AS user, password, CONCAT('/home/mail/', maildir) AS userdb_home, \ CONCAT('maildir:/home/mail/', maildir,'Maildir') AS userdb_mail, \ 500 AS userdb_uid, 500 AS userdb_gid \ FROM mailbox WHERE username = '%u' AND active = '1' connect = host=localhost dbname=postfixadmin user=postfixadmin password=postfixadmin map { pattern = priv/quota/storage table = quota2 username_field = username value_field = bytes } map { pattern = priv/quota/messages table = quota2 username_field = username value_field = messages } addgroup --system --gid 500 vmail mkdir /home/mail adduser --system --home /home/mail --shell /bin/false --no-create-home --uid 500 --gid 500 --disabled-password --disabled-login vmail chown vmail:vmail /home/mail/ /etc/init.d/dovecot restart /etc/init.d/postfix restart require ["fileinto" ]; # Los correos con "X-Spam-Flag" positivo a la basura if header :contains "X-Spam-Flag" "YES" { fileinto "Trash"; } # Los que tengan alguno de estos strings en el subject también elsif header :matches "Subject" ["*money*","*Viagra*","Cialis"] { fileinto "Trash"; } # Las listas de Debian al subdirectorio correspondiente if address :DOMAIN :is ["From", "To"] "lists.debian.org" { fileinto "Listas.Debian"; } # Y lo demás sin procesar (es decir, al INBOX) Comentarios (11) |