OpenBSD: Postfix + amavisd-new + spamasassin + clamav + postgrey + courier-imap + PostgreSQL + roundcube + postfixadmin (Beta).

Intentaré explicar esto lo más breve posible y que al mismo tiempo resulte fácil.

En primer lugar, vamos a instalar los ports:

cd /usr/ports/mail/postfix/stable

env FLAVOR=”sasl2 pgsql” make install clean

Con esto instalaremos la versión stable con soporte PostgreSQL. Recuerda activar el Postfix con las instrucciones que tienes después de la instalación.

cd /usr/ports/mail/courier-imap

make install clean

Con esto otro, Courier.

cd /usr/ports/mail/amavisd-new

make install clean

Con esto: amavisd-new.

cd /usr/ports/mail/postgrey

make install clean

También postgrey.

cd /usr/ports/databases/postgresql

make install clean

env SUBPACKAGE=”-server” make install clean

Esto instalará el cliente y el servidor de PostgreSQL.

Ahora empezamos con la configuración de Postfix.

/etc/postfix/main.cf:

queue_directory = /var/spool/postfix
command_directory = /usr/local/sbin
setgid_group = _postdrop
daemon_directory = /usr/local/libexec/postfix
mail_owner = _postfix
default_privs = nobody
default_transport = smtp
alias_maps = hash:/etc/postfix/aliases
alias_database = hash:/etc/postfix/aliases
readme_directory = no
sample_directory = /usr/local/etc/postfix
sendmail_path = /usr/local/sbin/sendmail
manpage_directory = /usr/local/man
newaliases_path = /usr/local/bin/newaliases
mailq_path = /usr/local/bin/mailq
smtpd_banner = $myhostname mail server
disable_vrfy_command = yes
myhostname=mail.tudominio.es

mydomain=tudominio.es

myorigin= $mydomain
mydestination= $mydomain, $transport_maps
virtual_alias_maps = pgsql:/etc/postfix/virtual_alias_maps.cnf
virtual_mailbox_base = /home/postfix
virtual_mailbox_maps = pgsql:/etc/postfix/virtual_mailbox_maps.cnf
virtual_uid_maps = pgsql:/etc/postfix/virtual_uid_maps.cnf
virtual_gid_maps = pgsql:/etc/postfix/virtual_gid_maps.cnf
transport_maps = pgsql:/etc/postfix/transport_maps.cnf, hash:/etc/postfix/transport
local_transport = virtual
local_recipient_maps = $virtual_mailbox_maps
virtual_mailbox_limit_inbox = no
virtual_mailbox_limit_maps= pgsql:/etc/postfix/virtual_mailbox_limit_maps.cnf
virtual_mailbox_limit_override = yes
virtual_maildir_extended = yes
virtual_create_maildirsize = yes
virtual_mailbox_limit = 100000000
virtual_maildir_limit_message = Mensaje a sobrepasado la quota de disco de esta cuenta
virtual_overquota_bounce = yes
smtpd_sasl_auth_enable = yes
smtpd_sasl_security_options = noanonymous
broken_sasl_auth_clients = yes
smtpd_recipient_restrictions =
permit_sasl_authenticated,
permit_mynetworks,
reject_unauth_destination,
check_policy_service inet:127.0.0.1:8888,
reject_rbl_client bl.spamcop.net,
reject_rbl_client cbl.abuseat.org,
reject_rbl_client sbl.spamhaus.org,
reject_rbl_client dnsbl.ahbl.org,
reject_rbl_client l1.spews.dnsbl.sorbs.net,
reject_rhsbl_client dnsbl.sorbs.net

dspam_destination_recipient_limit = 1
dspam_recipient_delimiter = -
smtpd_use_tls = yes
smtpd_tls_key_file = /etc/postfix/ssl/mail.dominio.es.key
smtpd_tls_cert_file = /etc/postfix/ssl/mail.dominio.es.crt
content_filter=smtp-amavis:127.0.0.1:10024

/etc/master.cf:

smtp inet n – – – – smtpd -o smtpd_use_tls=yes

Esa línea deberá quedar así.

smtp-amavis unix – – y – 2 smtp
-o smtp_data_done_timeout=1200
-o disable_dns_lookups=yes
127.0.0.1:10025 inet n – n – – smtpd
-o content_filter=
-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 smtpd_data_restrictions=reject_unauth_pipelining
-o smtpd_end_of_data_restrictions=
-o smtpd_restriction_classes=
-o mynetworks=127.0.0.0/8
-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_chec
ks,no_milters
-o local_header_rewrite_clients=

Y debemos agregar esto también.

/etc/postfix/virtual_alias_maps.cnf:

user = postfix
password= tupassword

dbname = postfix
table = alias
select_field = goto
where_field = address
hosts = 127.0.0.1
En este fichero como en los que vendrán más adelante, tendréis que acomodar la configuración dependiendo de la base de datos de cada uno, así como su estructura, host, etc.

/etc/postfix/virtual_gid_maps.cnf:

user=postfix
password = tupassword

dbname = postfix
table = mailbox
select_field = gid
where_field = username
hosts = 127.0.0.1

/etc/postfix/virtual_mailbox_limit_maps.cnf:

user = postfix
password =tupassword

dbname = postfix
table = mailbox
select_field = quota
where_field = username
hosts = 127.0.0.1
/etc/postfix/virtual_mailbox_maps.cnf:

user = postfix
password= tupassword
dbname = postfix
table = mailbox
select_field = maildir
where_field = username
hosts = 127.0.0.1
/etc/postfix/virtual_uid_maps.cnf:

user=postfix
password = tupassword
dbname = postfix
table = mailbox
select_field = uid
where_field = username
hosts = 127.0.0.1

Iniciamos Postfix:

/usr/local/sbin/postfix start

Courier-imap:

/etc/courier/authpgsqlrc:

PGSQL_HOST 127.0.0.1
PGSQL_USERNAME postfix
PGSQL_PASSWORD tupassword

PGSQL_PORT 5432
PGSQL_DATABASE postfix
PGSQL_USER_TABLE mailbox
PGSQL_CLEAR_PWFIELD password
PGSQL_UID_FIELD uid
PGSQL_GID_FIELD gid
PGSQL_LOGIN_FIELD username
PGSQL_HOME_FIELD home
PGSQL_NAME_FIELD name
PGSQL_MAILDIR_FIELD maildir
PGSQL_QUOTA_FIELD quota
PGSQL_WHERE_CLAUSE active=’t’

Omitiré la configuración de Amavisd-new ya que es bastante simple y además hay muchísimos documentos en la red acerca de cómo configurarlo.

La base de datos para postfix:

CREATE TABLE "admin" (
  "username" character varying(255) NOT NULL default '',
  "password" character varying(255) NOT NULL default '',
  "created" timestamp with time zone default now(),
  "modified" timestamp with time zone default now(),
  "active" boolean NOT NULL default true,
  Constraint "admin_key" Primary Key ("username")
);
COMMENT ON TABLE admin IS 'Postfix Admin - Virtual Admins';
--
-- Estructura tabla alias utilizada para guardar informacion de los alias de cuentas
--
CREATE TABLE alias (
 address character varying(255) NOT NULL default '',
 goto text NOT NULL,
 domain character varying(255) NOT NULL default '',
 created timestamp with time zone default now(),
 modified timestamp with time zone default now(),
 active boolean NOT NULL default true,
-- PRIMARY KEY ("address"),
-- KEY address ("address"),
 Constraint "alias_key" Primary Key ("address")
);
COMMENT ON TABLE alias IS 'Postfix Admin - Virtual Aliases';
--
-- Estructura tabla domain contiene informacion de los dominios que administra el servidor,
-- agregamos por defecto el virtual al campo transport
--
CREATE TABLE domain (
 domain character varying(255) NOT NULL default '',
 description character varying(255) NOT NULL default '',
 aliases integer NOT NULL default 0,
 mailboxes integer NOT NULL default 0,
 maxquota integer NOT NULL default 0,
 transport character varying(255) default 'virtual',
 backupmx smallint NOT NULL default 0,
 created timestamp with time zone default now(),
 modified timestamp with time zone default now(),
 active boolean NOT NULL default true,
-- PRIMARY KEY ("domain"),
-- KEY domain ("domain"),
 Constraint "domain_key" Primary Key ("domain")
);
COMMENT ON TABLE domain IS 'Postfix Admin - Virtual Domains';
--
-- Estructura tabla domain_admins contiene informacion acerca del usuario encargado de
-- administrar las cuentas del dominio especificado
--
CREATE TABLE domain_admins (
 username character varying(255) NOT NULL default '',
 domain character varying(255) NOT NULL default '',
 created timestamp with time zone default now(),
 active boolean NOT NULL default true
-- KEY username ("username")
);
COMMENT ON TABLE domain_admins IS 'Postfix Admin - Domain Admins';
--
-- Estructura tabla log contiene informacion de los cambios realizados usando postfixadmin
--
CREATE TABLE log (
 timestamp timestamp with time zone default now(),
 username character varying(255) NOT NULL default '',
 domain character varying(255) NOT NULL default '',
 action character varying(255) NOT NULL default '',
 data character varying(255) NOT NULL default ''
-- KEY timestamp ("timestamp")
);
COMMENT ON TABLE log IS 'Postfix Admin - Log';
--
-- Estructura tabla mailbox mantiene informacion referente a las cuentas de correo, agregamos
-- por defecto los valores 125 (postfix)  y 6 (nobody) a los campos uid y gid, tambien
-- especificamos el campo home para indicar la ruta base dode estaran los mailbox .
--
CREATE TABLE mailbox (
 username character varying(255) NOT NULL default '',
 password character varying(255) NOT NULL default '',
 name character varying(255) NOT NULL default '',
 home character varying(255) NOT NULL default '/home/postfix/',
 maildir character varying(255) NOT NULL default '',
 quota integer NOT NULL default 0,
 domain character varying(255) NOT NULL default '',
 created timestamp with time zone default now(),
 modified timestamp with time zone default now(),
 active boolean NOT NULL default true,
 uid integer NOT NULL default 125,
 gid integer NOT NULL default 6,
-- PRIMARY KEY ("username"),
-- KEY username ("username"),
 Constraint "mailbox_key" Primary Key ("username")
);
COMMENT ON TABLE mailbox IS 'Postfix Admin - Virtual Mailboxes';
--
-- Estructura dela tabla vacation usado para el servicio de vacation no lo usaremos pero
-- crearemos las tablas para evitar un error de postfixadim tambien podemos
-- obtar por modificar el postfixadmin
--
CREATE TABLE vacation (
 email character varying(255) NOT NULL default '',
 subject character varying(255) NOT NULL default '',
 body text NOT NULL,
 cache text NOT NULL,
 domain character varying(255) NOT NULL default '',
 created timestamp with time zone default now(),
 active boolean NOT NULL default true,
-- PRIMARY KEY ("email"),
-- KEY email ("email")
 Constraint "vacation_key" Primary Key ("email")
);
COMMENT ON TABLE vacation IS 'Postfix Admin - Virtual Vacation';
--
-- Asignamos privilegios para la base de datos
--
GRANT SELECT,INSERT,UPDATE,DELETE ON admin,alias,domain,domain_admins,log,mailbox,vacation
TO postfixadmin,postfix;
(Ambas líneas).

Nota: Base de datos sacada de aquí, documento escrito por ACMhunter para eldemonio.org

Recuerda que para instalar una base de datos, tienes que hacerlo como usuario _postgresql, con los siguientes comandos:

createdb -U postgres -O propietario basededatos

createuser -U postgres -E -P nombredeusuario

Luego nos conectamos como psql -U nombredeusuario basededatos

Una vez dentro, hacemos el volcado del fichero .sql con \i rutahastaelsql

Ahora vamos con el fichero /etc/rc.local:

if [ -x /usr/local/bin/pg_ctl ]; then
su -l _postgresql -c “nohup /usr/local/bin/pg_ctl start \
-D /var/postgresql/data -l /var/postgresql/logfile \
-o ‘-D /var/postgresql/data’”
echo -n ‘ postgresql’
fi

if [ -x /usr/local/sbin/clamd ]; then
echo ‘Starting clamav…’; /usr/local/sbin/clamd
fi

echo -n ‘ Courier-IMAP’
/bin/mkdir -p /var/run/courier && /bin/mkdir -p /var/run/courier-auth/
[ -x /usr/local/libexec/imapd.rc ] && /usr/local/libexec/imapd.rc start
[ -x /usr/local/libexec/imapd-ssl.rc ] && /usr/local/libexec/imapd-ssl.rc start
[ -x /usr/local/sbin/authdaemond ] && /usr/local/sbin/authdaemond start

if [ -x /usr/local/libexec/postgrey ]; then
/usr/local/libexec/postgrey –inet=127.0.0.1:8888 -d –delay=20
echo ‘postgrey ‘
fi

if [ -x /usr/local/sbin/amavisd ]; then
echo -n ‘ amavisd’; /usr/local/sbin/amavisd
fi

Todo esto tendremos que añadir a /etc/rc.local para arrancar los programas requeridos.

Pasamos a la configuración de roundcube. Lo podéis obtener de esta dirección.

Únicamente tendréis que crear la base de datos para él y ajustar los siguientes parámetros:

// postgres example: ‘pgsql://roundcube:pass@localhost/roundcubemail’;
Que viene a ser: usuario:password@host/basededatos

Luego postfixadmin:

Tenéis que editar el archivo config.inc.php y poner los parámetros correctamente, tal que así:

$CONF['database_type'] = ‘pgsql’;
$CONF['database_host'] = ’127.0.0.1′;
$CONF['database_user'] = ‘postfix’;
$CONF['database_password'] = ‘tupassword’;
$CONF['database_name'] = ‘postfix’;
$CONF['database_prefix'] = ”;

Revisad todo el documento, ya que existen debéis modificar aún más. Luego está lo de proteger el directorio, con login y password claro está.

En fin, espero que esto oriente a alguien o le sirva de ayuda y de nuevo os digo que el documento está en versión beta, y es muy posible que tenga fallos y se le puedan hacer mejoras… por lo que si véis que existe algún error o pensáis que se puede cambiar algún parámetro actualizaré el post/tutorial sin problemas.

Un saludo.

3 thoughts on “OpenBSD: Postfix + amavisd-new + spamasassin + clamav + postgrey + courier-imap + PostgreSQL + roundcube + postfixadmin (Beta).

  1. Jacob dice:

    Gracias por comentar.

    Están bien tus artículos, y también tu blog.

    Acabo de enlazarte, saludos.

  2. kde_tony dice:

    acabo de ponerlo en marcha en suse, y funcionó de las mil maravillas, excelento How-To

Deja un comentario

Tu dirección de correo electrónico no será publicada. Los campos necesarios están marcados *

*

Puedes usar las siguientes etiquetas y atributos HTML: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>