Alberto Garcia

Configuració del servidor de correu entrant corporatiu (dovecot)

El primer que farem serà actualitzar les llibreries instal·lades, per a després instal·lar els paquets necessaris amb l’última versió.

sudo apt update
sudo apt install dovecot-imapd dovecot-pop3d dovecot-lmtpd
Resultat comanda
vagrant@debian:~$ sudo apt install dovecot-imapd dovecot-pop3d
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
  dovecot-core libexttextcat-2.0-0 libexttextcat-data liblua5.4-0 libstemmer0d libunwind8
Suggested packages:
  dovecot-gssapi dovecot-ldap dovecot-lmtpd dovecot-lucene dovecot-managesieved dovecot-mysql dovecot-pgsql dovecot-sieve dovecot-solr
  dovecot-sqlite dovecot-submissiond ntp ufw
The following NEW packages will be installed:
  dovecot-core dovecot-imapd dovecot-pop3d libexttextcat-2.0-0 libexttextcat-data liblua5.4-0 libstemmer0d libunwind8
0 upgraded, 8 newly installed, 0 to remove and 26 not upgraded.
Need to get 7887 kB of archives.
After this operation, 17.4 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://deb.debian.org/debian bookworm/main amd64 libexttextcat-data all 3.4.5-1 [164 kB]
Get:2 http://deb.debian.org/debian bookworm/main amd64 libexttextcat-2.0-0 amd64 3.4.5-1 [15.9 kB]
Get:3 http://deb.debian.org/debian bookworm/main amd64 liblua5.4-0 amd64 5.4.4-3+deb12u1 [137 kB]
Get:4 http://deb.debian.org/debian bookworm/main amd64 libstemmer0d amd64 2.2.0-2 [118 kB]
Get:5 http://deb.debian.org/debian bookworm/main amd64 libunwind8 amd64 1.6.2-3 [51.2 kB]
Get:6 http://deb.debian.org/debian bookworm/main amd64 dovecot-core amd64 1:2.3.19.1+dfsg1-2.1+deb12u1 [4486 kB]
Get:7 http://deb.debian.org/debian bookworm/main amd64 dovecot-imapd amd64 1:2.3.19.1+dfsg1-2.1+deb12u1 [1528 kB]
Get:8 http://deb.debian.org/debian bookworm/main amd64 dovecot-pop3d amd64 1:2.3.19.1+dfsg1-2.1+deb12u1 [1386 kB]
Fetched 7887 kB in 0s (27.1 MB/s)   
apt-listchanges: Can't set locale; make sure $LC_* and $LANG are correct!
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
	LANGUAGE = "en_GB:en",
	LC_ALL = (unset),
	LC_MONETARY = "es_ES.UTF-8",
	LC_ADDRESS = "es_ES.UTF-8",
	LC_TELEPHONE = "es_ES.UTF-8",
	LC_NAME = "es_ES.UTF-8",
	LC_MEASUREMENT = "es_ES.UTF-8",
	LC_IDENTIFICATION = "es_ES.UTF-8",
	LC_NUMERIC = "es_ES.UTF-8",
	LC_PAPER = "es_ES.UTF-8",
	LANG = "en_GB.UTF-8"
    are supported and installed on your system.
perl: warning: Falling back to a fallback locale ("en_GB.UTF-8").
locale: Cannot set LC_ALL to default locale: No such file or directory
Selecting previously unselected package libexttextcat-data.
(Reading database ... 36690 files and directories currently installed.)
Preparing to unpack .../0-libexttextcat-data_3.4.5-1_all.deb ...
Unpacking libexttextcat-data (3.4.5-1) ...
Selecting previously unselected package libexttextcat-2.0-0:amd64.
Preparing to unpack .../1-libexttextcat-2.0-0_3.4.5-1_amd64.deb ...
Unpacking libexttextcat-2.0-0:amd64 (3.4.5-1) ...
Selecting previously unselected package liblua5.4-0:amd64.
Preparing to unpack .../2-liblua5.4-0_5.4.4-3+deb12u1_amd64.deb ...
Unpacking liblua5.4-0:amd64 (5.4.4-3+deb12u1) ...
Selecting previously unselected package libstemmer0d:amd64.
Preparing to unpack .../3-libstemmer0d_2.2.0-2_amd64.deb ...
Unpacking libstemmer0d:amd64 (2.2.0-2) ...
Selecting previously unselected package libunwind8:amd64.
Preparing to unpack .../4-libunwind8_1.6.2-3_amd64.deb ...
Unpacking libunwind8:amd64 (1.6.2-3) ...
Selecting previously unselected package dovecot-core.
Preparing to unpack .../5-dovecot-core_1%3a2.3.19.1+dfsg1-2.1+deb12u1_amd64.deb ...
Unpacking dovecot-core (1:2.3.19.1+dfsg1-2.1+deb12u1) ...
Selecting previously unselected package dovecot-imapd.
Preparing to unpack .../6-dovecot-imapd_1%3a2.3.19.1+dfsg1-2.1+deb12u1_amd64.deb ...
Unpacking dovecot-imapd (1:2.3.19.1+dfsg1-2.1+deb12u1) ...
Selecting previously unselected package dovecot-pop3d.
Preparing to unpack .../7-dovecot-pop3d_1%3a2.3.19.1+dfsg1-2.1+deb12u1_amd64.deb ...
Unpacking dovecot-pop3d (1:2.3.19.1+dfsg1-2.1+deb12u1) ...
Setting up libunwind8:amd64 (1.6.2-3) ...
Setting up libexttextcat-data (3.4.5-1) ...
Setting up liblua5.4-0:amd64 (5.4.4-3+deb12u1) ...
Setting up libstemmer0d:amd64 (2.2.0-2) ...
Setting up libexttextcat-2.0-0:amd64 (3.4.5-1) ...
Setting up dovecot-core (1:2.3.19.1+dfsg1-2.1+deb12u1) ...
locale: Cannot set LC_ALL to default locale: No such file or directory

Creating config file /etc/dovecot/dovecot.conf with new version
locale: Cannot set LC_ALL to default locale: No such file or directory

Creating config file /etc/dovecot/dovecot-dict-auth.conf.ext with new version
locale: Cannot set LC_ALL to default locale: No such file or directory

Creating config file /etc/dovecot/dovecot-dict-sql.conf.ext with new version
locale: Cannot set LC_ALL to default locale: No such file or directory

Creating config file /etc/dovecot/dovecot-sql.conf.ext with new version
locale: Cannot set LC_ALL to default locale: No such file or directory

Creating config file /etc/dovecot/conf.d/10-auth.conf with new version
locale: Cannot set LC_ALL to default locale: No such file or directory

Creating config file /etc/dovecot/conf.d/10-director.conf with new version
locale: Cannot set LC_ALL to default locale: No such file or directory

Creating config file /etc/dovecot/conf.d/10-logging.conf with new version
locale: Cannot set LC_ALL to default locale: No such file or directory

Creating config file /etc/dovecot/conf.d/10-mail.conf with new version
locale: Cannot set LC_ALL to default locale: No such file or directory

Creating config file /etc/dovecot/conf.d/10-master.conf with new version
locale: Cannot set LC_ALL to default locale: No such file or directory

Creating config file /etc/dovecot/conf.d/10-ssl.conf with new version
locale: Cannot set LC_ALL to default locale: No such file or directory

Creating config file /etc/dovecot/conf.d/10-tcpwrapper.conf with new version
locale: Cannot set LC_ALL to default locale: No such file or directory

Creating config file /etc/dovecot/conf.d/15-lda.conf with new version
locale: Cannot set LC_ALL to default locale: No such file or directory

Creating config file /etc/dovecot/conf.d/15-mailboxes.conf with new version
locale: Cannot set LC_ALL to default locale: No such file or directory

Creating config file /etc/dovecot/conf.d/90-acl.conf with new version
locale: Cannot set LC_ALL to default locale: No such file or directory

Creating config file /etc/dovecot/conf.d/90-plugin.conf with new version
locale: Cannot set LC_ALL to default locale: No such file or directory

Creating config file /etc/dovecot/conf.d/90-quota.conf with new version
locale: Cannot set LC_ALL to default locale: No such file or directory

Creating config file /etc/dovecot/conf.d/auth-checkpassword.conf.ext with new version
locale: Cannot set LC_ALL to default locale: No such file or directory

Creating config file /etc/dovecot/conf.d/auth-deny.conf.ext with new version
locale: Cannot set LC_ALL to default locale: No such file or directory

Creating config file /etc/dovecot/conf.d/auth-dict.conf.ext with new version
locale: Cannot set LC_ALL to default locale: No such file or directory

Creating config file /etc/dovecot/conf.d/auth-master.conf.ext with new version
locale: Cannot set LC_ALL to default locale: No such file or directory

Creating config file /etc/dovecot/conf.d/auth-passwdfile.conf.ext with new version
locale: Cannot set LC_ALL to default locale: No such file or directory

Creating config file /etc/dovecot/conf.d/auth-sql.conf.ext with new version
locale: Cannot set LC_ALL to default locale: No such file or directory

Creating config file /etc/dovecot/conf.d/auth-static.conf.ext with new version
locale: Cannot set LC_ALL to default locale: No such file or directory

Creating config file /etc/dovecot/conf.d/auth-system.conf.ext with new version
Created symlink /etc/systemd/system/multi-user.target.wants/dovecot.service → /lib/systemd/system/dovecot.service.
dovecot.socket is a disabled or a static unit, not starting it.
Setting up dovecot-imapd (1:2.3.19.1+dfsg1-2.1+deb12u1) ...
locale: Cannot set LC_ALL to default locale: No such file or directory

Creating config file /etc/dovecot/conf.d/20-imap.conf with new version
Setting up dovecot-pop3d (1:2.3.19.1+dfsg1-2.1+deb12u1) ...
locale: Cannot set LC_ALL to default locale: No such file or directory

Creating config file /etc/dovecot/conf.d/20-pop3.conf with new version
Processing triggers for man-db (2.11.2-2) ...
Processing triggers for libc-bin (2.36-9+deb12u13) ...
Processing triggers for dovecot-core (1:2.3.19.1+dfsg1-2.1+deb12u1)

Ara el que farem serà entrar en la configuració del programa dovecot, i el que volem configurar està a l’arxiu dovecot.conf .

sudo vim /etc/dovecot/dovecot.conf 

I una vegada dintre del arxiu de configuracio afegirem aquesta linea justament debaix de on posi sobre els protoc s

# 1. Protocols: Ara sí, tenim IMAP, POP3 i LMTP instal·lats
protocols = imap pop3 lmtp

I per l’Emmagatzematge usarem maldir en lloc d’Mbox perquè cada correu es guarda en un fitxer separat. Això evita bloquejos de fitxers i corrupció de dades quan diversos dispositius accedeixen a la bústia alhora, i per utilitzar-ho afegirem la següent línia al mateix arxiu que la configuració dels protocols. 

mail_location = maildir:~/Maildir.

Y la ultima configuracio sera afegir la validacio dels usuaris, aixo ho farem afegin aixo al final .

userdb {
  driver = passwd
}
passdb {
  driver = pam
}
Configuracio final
# --- CONFIGURACIO dovecot.conf GRUP3) ---

# 1. Com ya els tenim instalats els activaren amb la seguent linea.
protocols = imap pop3 lmtp

# 2. Xarxa: Escolta a totes les interfícies
listen = *, ::

# 3. Emmagatzematge: Maildir
mail_location = maildir:~/Maildir

# 6. Autenticacio 
userdb {
  driver = passwd
}
passdb {
  driver = pam
}

La primera comprovacio que hem de fer es reiniciar el servei, per que se apliquin les configuracions i veure si inicia be el servei, si no dona ningun error farem status per veure si esta tot be iniciat 

sudo systemctl restart dovecot
sudo systemctl status dovecot
vagrant@debian:~$ sudo systemctl restart dovecot
vagrant@debian:~$ systemctl status
● debian
    State: running
    Units: 250 loaded (incl. loaded aliases)
     Jobs: 0 queued
   Failed: 0 units
    Since: Wed 2026-01-14 08:23:45 CET; 1h 21min ago
  systemd: 252.39-1~deb12u1

Ara que ja esta el servei actiu farem una prova de connexió real.

  1. telnet localhost 110 (per POP3)

  2. telnet localhost 143 (per IMAP).

telnet localhost 110
telnet localhost 143
vagrant@debian:~$ telnet localhost 110
Trying ::1...
Connected to localhost.
Escape character is '^]'.
+OK Dovecot (Debian) ready.
vagrant@debian:~$ telnet localhost 143
Trying ::1...
Connected to localhost.
Escape character is '^]'.
* OK [CAPABILITY IMAP4rev1 SASL-IR LOGIN-REFERRALS ID ENABLE IDLE LITERAL+ STARTTLS AUTH=PLAIN] Dovecot (Debian) ready.

I per ultim per verificar que el servidor gestiona correctament les bústies dels usuaris, hem comprovat la creació automàtica del directori Maildir.

Hem utilitzat l’eina de Dovecot per forçar la indexació de la bústia de l’usuari i despres farem un llistat del contigunt de la carpeta del usuari.

sudo doveadm mailbox status -u alumne3 all INBOX
sudo ls -R /home/alumne3/Maildir
vagrant@debian:~$ sudo ls -R /home/alumne3/Maildir
/home/alumne3/Maildir:
cur  dovecot-uidlist  dovecot-uidvalidity  dovecot-uidvalidity.69676475  dovecot.index.log  dovecot.list.index.log  new  tmp

/home/alumne3/Maildir/cur:

/home/alumne3/Maildir/new:

/home/alumne3/Maildir/tmp: