Banner

Showing posts with label correo postfix dovecot. Show all posts
Showing posts with label correo postfix dovecot. Show all posts

5/11/2010

Como hacer un servidor de correo con Ubuntu,Postfix, Dovecot y Getmail


El objetivo es crear un servidor de correo mediante imap, para una red local, la mensajería saliente siendo enviada y recogida para nosotros por un servidor padre o relayhost...


#ll#1 instalar los servicios necesarios
sudo aptitude install postfix sasl2-bin dovecot-imapd getmail4 telnet

#2 Configurar postfix
sudo dpkg-reconfigure postfix -llenar con la informacion pertinente, ejemplo a continuación:
General type of mail configuration: Satellyte Site #porque somos satelites de un ISP, de lo contrario por defecto ;)
System mail name: ej:ejemplo.cu
Root and postmaster mail recipient: ej:user
Other destinations for mail: ejemplo.cu server.ejemplo.cu, ejemplo.cu, localhost.ejemplo.cu, localhost
Force synchronous updates on mail queue?: No
Local networks: 127.0.0.0/8 172.0.0.1
Mialbox size limit (bytes): 0 ej:20000
Local address extension character: +
Internet protocols to use: ipv4

#3 Establecer el tipo de formato de buzon y el modelo de autenticacion[SMTP AUTH utilizando SASL(saslauthd)]
sudo postconf -e 'home_mailbox = Maildir/'
sudo postconf -e 'mailbox_command ='
sudo postconf -e 'smtpd_sasl_local_domain ='
sudo postconf -e 'smtpd_sasl_auth_enable = yes'
sudo postconf -e 'smtpd_sasl_security_options = noanonymous'
sudo postconf -e 'broken_sasl_auth_clients = yes'
sudo postconf -e 'smtpd_recipient_restrictions = permit_sasl_authenticated,permit_mynetworks,reject_unauth_destination'
sudo postconf -e 'inet_interfaces = all' #importante

#5 establecer el tipo de autenticacion
sudo nano /etc/postfix/sasl/smtpd.conf
#escribir
pwcheck_method: saslauthd
mech_list: plain login

#6 Generar el certificado TSL utilizado para la encriptacion
touch smtpd.key
chmod 600 smtpd.key
openssl genrsa 1024 > smtpd.key
openssl req -new -key smtpd.key -x509 -days 3650 -out smtpd.crt # llena los datos que te pide
openssl req -new -x509 -extensions v3_ca -keyout cakey.pem -out cacert.pem -days 3650 # llena los datos que te pide
sudo mv smtpd.key /etc/ssl/private/
sudo mv smtpd.crt /etc/ssl/certs/
sudo mv cakey.pem /etc/ssl/private/
sudo mv cacert.pem /etc/ssl/certs/

#7 Configurar postfix para encriptar el logueo
sudo postconf -e 'smtp_tls_security_level = may'
sudo postconf -e 'smtpd_tls_security_level = may'
sudo postconf -e 'smtpd_tls_auth_only = no'
sudo postconf -e 'smtp_tls_note_starttls_offer = yes'
sudo postconf -e 'smtpd_tls_key_file = /etc/ssl/private/smtpd.key'
sudo postconf -e 'smtpd_tls_cert_file = /etc/ssl/certs/smtpd.crt'
sudo postconf -e 'smtpd_tls_CAfile = /etc/ssl/certs/cacert.pem'
sudo postconf -e 'smtpd_tls_loglevel = 1'
sudo postconf -e 'smtpd_tls_received_header = yes'
sudo postconf -e 'smtpd_tls_session_cache_timeout = 3600s'
sudo postconf -e 'tls_random_source = dev:/dev/urandom'
sudo postconf -e 'myhostname = correo.ejemplo.cu' # cambiar por nombre de tu servidor

##Opcional##########################################
#8Luego para mapear los usuarios del dominio virtual al real
sudo postconf -e 'smtp_generic_maps = hash:/etc/postfix/generic'
sudo nano /etc/postfix/generic
user@ejemplo.cu user@google.com
user1@ejemplo.cu user1@google.com
...
sudo postmap /etc/postfix/generic
##Opcional##########################################

#9 Configurar Postfix para usar SASL para SMTP AUTH
#editar /etc/default/saslauthd
#establecer los siguientes parametros, copiar los que falten
START=yes
PWDIR="/var/spool/postfix/var/run/saslauthd"
PARAMS="-m ${PWDIR}"
PIDFILE="${PWDIR}/saslauthd.pid"
OPTIONS="-c -m /var/spool/postfix/var/run/saslauthd"

#10actualizar el estado del saslauthd para postfix, ignorar warnings
sudo dpkg-statoverride --force --update --add root sasl 755 /var/spool/postfix/var/run/saslauthd
sudo /etc/init.d/saslauthd start

#11 Probar si sirvio
#establecer coneccion:
telnet localhost 25
#luego:
ehlo localhost
#si muestra algo asi:
250-STARTTLS
250-AUTH ...
#esta funcionando bien la autenticacion sasl

#12 Dovecot

#12.1Para usar NFS en el buzón.
$ sudo nano /etc/dovecot/dovecot.conf
mmap_disable=yes
mail_nfs_storage = yes
mail_nfs_index = yes

#12.2Cuotas
En la seccion ## IMAP specific settings
mail_plugins = quota imap_quota
imap_client_workarounds = tb-extra-mailbox-sep delay-newmail
##al final en plugins
quota = maildir
quota_rule = *:storage=51200
quota_warning = storage=95%% /usr/local/bin/quota-warning.sh 95
quota_warning2 = storage=80%% /usr/local/bin/quota-warning.sh 80
##contenido del /usr/local/bin/quota-warning.sh:
sudo nano /usr/local/bin/quota-warning.sh
#!/bin/sh
PERCENT=$1
cat << EOF | /usr/local/libexec/dovecot/deliver -d $USER -c /usr/local/etc/dovecot-nowarning.conf
From: postmaster@ejemplo.cu
Subject: quota warning
Your mailbox is now $PERCENT% full.
EOF
##o cualquier otra cosa mas o menos asi ;)
sudo chmod 777 /usr/local/bin/quota-warning.sh

#13 Usuarios
ej:user, se utilizara tambien para getmail OJOOOOO!!!
$ sudo useradd user
$ sudo passwd user
$ sudo mkdir /home/user
$ sudo chown -R user: /home/user
$ cd /home/user
$ sudo su user
$ mkdir -m 0700 ~/.getmail
$ nano ~/.getmail/getmailrc
#############################################
-se borran los mensages del servidor padre
-message_log a un fichero log dentro del home
#############################################
[options]
verbose = 0
delete = true
message_log = ~/.getmail/log
[retriever]
type = SimplePOP3Retriever
server = 172.3.0.7
username = user@ejemplo.cu
password = password
[destination]
type = Maildir
path = ~/Maildir/
###############################################
-no se borran los mensages del servidor padre
hasta pasados 10 dias
-message_log hacia syslog
-solo descarga los nuevos
###############################################
[options]
verbose = 1
read_all = false
delete_after = 10
message_log_syslog = true
[retriever]
type = SimplePOP3Retriever
server = 172.3.0.7
username = user@ejemplo.cu
password = password
[destination]
type = Maildir
path = ~/Maildir/
###############################################
$ getmail # para probar
$ crontab -e
###############################################
revisar correo cada 5segundos
##############################################
*/5 * * * * getmail 2>/dev/null
##############################################

14#Finalizando
sudo /etc/init.d/dovecot restart
sudo /etc/init.d/postfix restart
sudo reboot

#15 Configurar cliente por IMAP y SASL ;)