Liens
Description
Postfix is a SMTP (Simple Mail Transfer Protocol) server.
Ports
- incoming 25 to receive emails from other SMTP servers
- outgoing 25 to send emails to other SMTP servers
- incoming 25 to allow SMTP client to connect and send emails
- incoming 587 to allow SMTP client to connect and send emails
Commands
|
sudo postfix check
sudo postfix reload
postconf -pf
postconf -df
|
/etc/postfix/main.cf
|
mydomain = domain.net
myhostname = mail.domain.net
myorigin = $mydomain
mydestination = $myhostname localhost.$mydomain localhost $mydomain
alias_maps = hash:/etc/aliases
mynetworks_style = host
relay_domains =
relayhost = [smtp.internet-provider.fr]
|
hostname
 |
Not sure that it is needed if localhost is used. |
|
hostnamectl status
sudo hostnamectl set-hostname mail.domain.fr
|
/etc/hosts
|
127.0.0.1 localhost mail.domain.fr
::1 localhost ip6-localhost ip6-loopback mail.domain.fr
|
|
hostname -f
|
/etc/postfix/main.cf
|
smtp_use_tls = yes
smtp_tls_security_level = encrypt
smtp_tls_note_starttls_offer = yes
smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache
|
 |
La box d’Orange bloque le port 25 en sortie ipv4 pour limiter l’envoi de spam.
L'envoie d'email doit donc se faire via le smtp d'orange. |
/etc/postfix/main.cf
|
relayhost = [smtp.orange.fr]:587
smtp_sasl_password_maps = hash:/etc/postfix/sasl/orange.conf
smtp_sasl_auth_enable = yes
smtp_sasl_security_options = noanonymous
|
/etc/postfix/sasl/orange.conf
|
[smtp.orange.fr]:587 compte@orange.fr:password
|
|
sudo postmap hash:/etc/postfix/sasl/orange.conf
sudo chmod 600 /etc/postfix/sasl/orange.conf
sudo chmod 600 /etc/postfix/sasl/orange.conf.db
|
/etc/postfix/main.cf
|
smtpd_tls_security_level = may
smtpd_tls_key_file = /etc/letsencrypt/live/domain.net/privkey.pem
smtpd_tls_cert_file = /etc/letsencrypt/live/domain.net/fullchain.pem
smtpd_tls_received_header = yes
smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache
smtpd_tls_loglevel = 1
|
Postfix supports the Dovecot SASL (Simple Authentication and Security Layer) implementation.
Dovecot is a POP/IMAP (Post Office Protocol / Interactive Message Access Protocol) server, it has its own configuration to authenticate POP/IMAP clients.
Communication between the Postfix SMTP server and Dovecot SASL happens over a UNIX-domain socket.
/etc/postfix/main.cf
|
smtpd_sasl_type = dovecot
smtpd_sasl_auth_enable = yes
smtpd_recipient_restrictions = permit_sasl_authenticated, permit_mynetworks, reject_unauth_destination
smtpd_sasl_path = private/auth
|
Allow incoming port 587 (submission)
By default Postfix listen incoming STMP client connections from port 25.
In addition you may allow the port 587 to receive incoming connections from SMTP client to send emails.
/etc/postfix/master.cf
|
submission inet n - y - - smtpd
-o syslog_name=postfix/submission
-o smtpd_tls_security_level=encrypt
-o smtpd_sasl_auth_enable=yes
-o smtpd_tls_auth_only=yes
-o smtpd_reject_unlisted_recipient=no
-o smtpd_client_restrictions=$mua_client_restrictions
-o smtpd_helo_restrictions=$mua_helo_restrictions
-o smtpd_sender_restrictions=$mua_sender_restrictions
-o smtpd_recipient_restrictions=
-o smtpd_relay_restrictions=permit_sasl_authenticated,reject
-o milter_macro_daemon_name=ORIGINATING
|
/etc/postfix/main.cf
|
mua_client_restrictions = permit_sasl_authenticated, reject
mua_sender_restrictions = permit_sasl_authenticated, reject
mua_helo_restrictions = permit_mynetworks, reject_invalid_hostname, permit
smtpd_restriction_classes = mua_sender_restrictions, mua_client_restrictions, mua_helo_restrictions
|
|
apt install opendkim opendkim-tools
|
/etc/opendkim.conf
|
Domain domain.fr
KeyFile /etc/dkimkeys/dkim.key
Selector mail
Canonicalization relaxed/simple
Socket local:/var/spool/postfix/var/run/opendkim/opendkim.sock
|
/etc/default/opendkim
|
RUNDIR=/var/spool/postfix/var/run/opendkim
|
|
opendkim-genkey -r -s mail -b 2048 -d domain.fr
sudo mv mail.private /etc/dkimkeys/dkim.key
sudo adduser postfix opendkim
sudo mkdir -p /var/spool/postfix/var/run/opendkim
sudo chown opendkim:opendkim /var/spool/postfix/var/run/opendkim
|
|
mail._domainkey.domain.fr. IN TXT "v=DKIM1
# mail: selector
# domain.fr: domain
# v: version
# h: hash / algorithme
# k: type de clé
# s: type de service
# p: clé publique base64
|
/etc/postfix/main.cf
|
non_smtpd_milters = unix:var/run/opendkim/opendkim.sock
smtpd_milters = unix:var/run/opendkim/opendkim.sock
|
Aliases
/etc/aliases
|
postmaster: <user>
root: <user>
|
|
sudo newaliases
|
/etc/postfix/main.cf
|
transport_maps = hash:/etc/postfix/transport
|
- emails sent to your own domain are delivered locally
- email sent to gmail.com are delivered normally by performing MX lookup
- all other emails are delivered via the relay host
/etc/postfix/transport
|
your-domain.com local
gmail.com smtp
* relay:[smtp-relay.sendinblue.com]:587
|
|
sudo postmap /etc/postfix/transport
|
Test
|
telnet localhost 25
ehlo localhost
mail from: root@domain.fr
rcpt to: user@gmail.com
data
subject: test
test
.
quit
|
Log
- journalctl
- /var/log/mail.log
- /var/log/mail.err
Mailboxes
By default Postifx will use mbox for the mailbox format.
/etc/postfix/main.cf
|
home_mailbox = maildir/
mailbox_command =
|
UFW
|
sudo ufw allow Postfix
|
Installation
|
apt install postfix
|
Erreurs
Our system has detected that 550-5.7.1 this message does not meet IPv6 sending guidelines
Our system has detected that 550-5.7.1 this message does not meet IPv6 sending guidelines regarding PTR 550-5.7.1 records and authentication.
Please review 550-5.7.1 https://support.google.com/mail/?p=IPv6AuthError for more information 550 5.7.1 .
/etc/postfix/main.cf
|
inet_protocols = ipv4
|