Postfix e Dovecot · 3 min read · Nov 21, 2025
Il Server Perfetto - CentOS 5.2 x86_64 - Pagina 5
11 Postfix Con SMTP-AUTH E TLS
Ora installiamo Postfix e Dovecot (Dovecot sarà il nostro server POP3/IMAP):
yum install cyrus-sasl cyrus-sasl-devel cyrus-sasl-gssapi cyrus-sasl-md5 cyrus-sasl-plain postfix dovecotSuccessivamente configuriamo SMTP-AUTH e TLS:
postconf -e 'smtpd_sasl_local_domain ='
postconf -e 'smtpd_sasl_auth_enable = yes'
postconf -e 'smtpd_sasl_security_options = noanonymous'
postconf -e 'broken_sasl_auth_clients = yes'
postconf -e 'smtpd_sasl_authenticated_header = yes'
postconf -e 'smtpd_recipient_restrictions = permit_sasl_authenticated,permit_mynetworks,reject_unauth_destination'
postconf -e 'inet_interfaces = all'
postconf -e 'mynetworks = 127.0.0.0/8'Dobbiamo modificare /usr/lib64/sasl2/smtpd.conf in modo che Postfix consenta accessi PLAIN e LOGIN. Dovrebbe apparire così:
vi /usr/lib64/sasl2/smtpd.conf| pwcheck_method: saslauthd mech_list: plain login |
Dopo creiamo i certificati per TLS:
mkdir /etc/postfix/ssl
cd /etc/postfix/ssl/
openssl genrsa -des3 -rand /etc/hosts -out smtpd.key 1024chmod 600 smtpd.key
openssl req -new -key smtpd.key -out smtpd.csropenssl x509 -req -days 3650 -in smtpd.csr -signkey smtpd.key -out smtpd.crtopenssl rsa -in smtpd.key -out smtpd.key.unencryptedmv -f smtpd.key.unencrypted smtpd.key
openssl req -new -x509 -extensions v3_ca -keyout cakey.pem -out cacert.pem -days 3650Successivamente configuriamo Postfix per TLS:
postconf -e 'smtpd_tls_auth_only = no'
postconf -e 'smtp_use_tls = yes'
postconf -e 'smtpd_use_tls = yes'
postconf -e 'smtp_tls_note_starttls_offer = yes'
postconf -e 'smtpd_tls_key_file = /etc/postfix/ssl/smtpd.key'
postconf -e 'smtpd_tls_cert_file = /etc/postfix/ssl/smtpd.crt'
postconf -e 'smtpd_tls_CAfile = /etc/postfix/ssl/cacert.pem'
postconf -e 'smtpd_tls_loglevel = 1'
postconf -e 'smtpd_tls_received_header = yes'
postconf -e 'smtpd_tls_session_cache_timeout = 3600s'
postconf -e 'tls_random_source = dev:/dev/urandom'Poi impostiamo il nome host nella nostra installazione di Postfix (assicurati di sostituire server1.example.com con il tuo nome host):
postconf -e 'myhostname = server1.example.com'Dopo questi passaggi di configurazione dovresti avere un /etc/postfix/main.cf che appare così (ho rimosso tutti i commenti):
cat /etc/postfix/main.cf| queue_directory = /var/spool/postfix command_directory = /usr/sbin daemon_directory = /usr/libexec/postfix mail_owner = postfix inet_interfaces = all mydestination = $myhostname, localhost.$mydomain, localhost unknown_local_recipient_reject_code = 550 alias_maps = hash:/etc/aliases alias_database = hash:/etc/aliases debug_peer_level = 2 debugger_command = PATH=/bin:/usr/bin:/usr/local/bin:/usr/X11R6/bin xxgdb $daemon_directory/$process_name $process_id & sleep 5 sendmail_path = /usr/sbin/sendmail.postfix newaliases_path = /usr/bin/newaliases.postfix mailq_path = /usr/bin/mailq.postfix setgid_group = postdrop html_directory = no manpage_directory = /usr/share/man sample_directory = /usr/share/doc/postfix-2.3.3/samples readme_directory = /usr/share/doc/postfix-2.3.3/README_FILES smtpd_sasl_local_domain = smtpd_sasl_auth_enable = yes smtpd_sasl_security_options = noanonymous broken_sasl_auth_clients = yes smtpd_sasl_authenticated_header = yes smtpd_recipient_restrictions = permit_sasl_authenticated,permit_mynetworks,reject_unauth_destination mynetworks = 127.0.0.0/8 smtpd_tls_auth_only = no smtp_use_tls = yes smtpd_use_tls = yes smtp_tls_note_starttls_offer = yes smtpd_tls_key_file = /etc/postfix/ssl/smtpd.key smtpd_tls_cert_file = /etc/postfix/ssl/smtpd.crt smtpd_tls_CAfile = /etc/postfix/ssl/cacert.pem smtpd_tls_loglevel = 1 smtpd_tls_received_header = yes smtpd_tls_session_cache_timeout = 3600s tls_random_source = dev:/dev/urandom myhostname = server1.example.com |
Per impostazione predefinita, il demone Dovecot di CentOS fornisce solo servizi IMAP e IMAPs. Poiché vogliamo anche POP3 e POP3s, dobbiamo configurare Dovecot per farlo. Modifichiamo /etc/dovecot.conf e abilitiamo la riga protocols = imap imaps pop3 pop3s:
vi /etc/dovecot.conf| [...] # Directory base dove memorizzare i dati di runtime. #base_dir = /var/run/dovecot/ # Protocolli che vogliamo servire: imap imaps pop3 pop3s # Se vuoi solo usare dovecot-auth, puoi impostarlo su "none". protocols = imap imaps pop3 pop3s # Indirizzo IP o host dove ascoltare le connessioni. Attualmente non è # possibile specificare indirizzi multipli. "*" ascolta in tutte le interfacce IPv4. # "[::]" ascolta in tutte le interfacce IPv6, ma può anche ascoltare in tutte le interfacce IPv4 # a seconda del sistema operativo. [...] |
Ora avvia Postfix, saslauthd e Dovecot:
chkconfig --levels 235 sendmail off
chkconfig --levels 235 postfix on
chkconfig --levels 235 saslauthd on
chkconfig --levels 235 dovecot on
/etc/init.d/sendmail stop
/etc/init.d/postfix start
/etc/init.d/saslauthd start
/etc/init.d/dovecot startPer vedere se SMTP-AUTH e TLS funzionano correttamente, esegui il seguente comando:
telnet localhost 25Dopo aver stabilito la connessione al tuo server di posta Postfix, digita
ehlo localhostSe vedi le righe
250-STARTTLSe
250-AUTH LOGIN PLAINtutto va bene.
[root@server1 ssl]# telnet localhost 25
Trying 127.0.0.1...
Connected to localhost.localdomain (127.0.0.1).
Escape character is '^]'.
220 server1.example.com ESMTP Postfix
ehlo localhost
250-server1.example.com
250-PIPELINING
250-SIZE 10240000
250-VRFY
250-ETRN
250-STARTTLS
250-AUTH LOGIN PLAIN
250-AUTH=LOGIN PLAIN
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN
qiot
502 5.5.2 Error: command not recognized
quit
221 2.0.0 Bye
Connection closed by foreign host.
[root@server1 ssl]#Digita
quitper tornare alla shell del sistema.
11.1 Maildir
Dovecot utilizza il formato Maildir (non mbox), quindi se installi ISPConfig sul server, assicurati di abilitare Maildir sotto Gestione -> Server -> Impostazioni -> Email. ISPConfig eseguirà quindi la configurazione necessaria.
Se non vuoi installare ISPConfig, allora devi configurare Postfix per consegnare le email nella Maildir di un utente (puoi anche farlo se usi ISPConfig - non fa male ;-)):
postconf -e 'home_mailbox = Maildir/'
postconf -e 'mailbox_command ='
/etc/init.d/postfix restartRicevi i nuovi post nella tua casella di posta.
Nessuno spam. Disiscriviti in qualsiasi momento.