Installation des pré-requis
sudo apt-get install postfix libsasl2-modules mailutils
Configuration du relais SMTP
sudo nano /etc/postfix/sasl_passwd
# contenu :
[smtp.mandrillapp.com]:587 key@domaine.fr:secret
# puis :
sudo postmap /etc/postfix/sasl_passwd
sudo chown root:root /etc/postfix/sasl_passwd /etc/postfix/sasl_passwd.db
sudo chmod 0600 /etc/postfix/sasl_passwd /etc/postfix/sasl_passwd.db
Configuration de Postfix
sudo nano /etc/postfix/main.cf
(...)
relayhost = [smtp.mandrillapp.com]:587
(...)
smtp_sasl_auth_enable = yes
smtp_sasl_security_options = noanonymous
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_use_tls = yes
smtputf8_enable = no
#
sudo service postfix restart
smtputf8_enable
à no
permet de résoudre l’erreur status=bounced (SMTPUTF8 is required, but was not offered by host smtp.mandrillapp.com)
qui se produit quand on ajoute des accents dans l’objet du message.
Envoi
echo "body of your email" | mail -s "This is a subject" -a "From:moi@domaine.fr" toi@domaine.fr
Ou :
mail -s "This is a subject" -a "From:moi@domaine.fr" toi@domaine.fr
<<< "body of your email"
Vérification
sudo tail -f /var/log/mail.log
Feb 27 10:16:41 xps postfix/pickup[179376]: A6232EE21C1: uid=1000 from=<moi@domaine.fr>
Feb 27 10:16:41 xps postfix/cleanup[180670]: A6232EE21C1: message-id=<20220227091641.A6232EE21C1@xps.local>
Feb 27 10:16:41 xps postfix/qmgr[179377]: A6232EE21C1: from=<moi@domaine.fr>, size=344, nrcpt=1 (queue active)
Feb 27 10:16:42 xps postfix/smtp[180676]: A6232EE21C1: to=<toi@domaine.fr>, relay=smtp.mandrillapp.com[34.241.27.172]:587, delay=0.35, delays=0.02/0.01/0.27/0.06, dsn=2.0.0, status=sent (250 2.0.0 Ok: queued as EE16B25836)
Feb 27 10:16:42 xps postfix/qmgr[179377]: A6232EE21C1: removed
Sources :
- https://www.linode.com/docs/guides/postfix-smtp-debian7/
- https://serverfault.com/questions/325955/no-worthy-mechs-found-when-trying-to-relay-email-to-gmail-using-postfix
Remarque concernant le paramètre « relayhost »
Si vous voulez envoyer des emails à xxx@domaine.fr, ne mettez PAS domaine.fr dans la variable relayhost
(cette valeur vous sera demandée lors de l’installation de Postfix). Sinon, vous mails seront délivrés localement sans même passer par le relais SMTP.