MSMTP
(Page créée avec « == Présentation == Cette page a pour objet de décrire comment installer MSMTP sur un serveur CentOS == Description == ''msmtp est un client SMTP très simple et facile… ») |
|||
(4 révisions intermédiaires par le même utilisateur non affichées) | |||
Ligne 25 : | Ligne 25 : | ||
Exemple de retour : | Exemple de retour : | ||
{{terminal|text= | {{terminal|text= | ||
− | [root@ | + | [root@myserver ~]# yum install msmtp |
Modules complémentaires chargés : fastestmirror | Modules complémentaires chargés : fastestmirror | ||
Loading mirror speeds from cached hostfile | Loading mirror speeds from cached hostfile | ||
Ligne 59 : | Ligne 59 : | ||
Dépendances résolues | Dépendances résolues | ||
− | ============================================================================================================================================================================================================================================= | + | ============================================================================================================================================================================================================================================== |
Package Architecture Version Dépôt Taille | Package Architecture Version Dépôt Taille | ||
− | ============================================================================================================================================================================================================================================= | + | ============================================================================================================================================================================================================================================== |
Installation : | Installation : | ||
msmtp x86_64 1.8.10-1.el7 epel 174 k | msmtp x86_64 1.8.10-1.el7 epel 174 k | ||
Ligne 73 : | Ligne 73 : | ||
Résumé de la transaction | Résumé de la transaction | ||
− | ============================================================================================================================================================================================================================================= | + | ============================================================================================================================================================================================================================================== |
Installation 1 Paquet (+6 Paquets en dépendance) | Installation 1 Paquet (+6 Paquets en dépendance) | ||
Ligne 125 : | Ligne 125 : | ||
Terminé ! | Terminé ! | ||
}} | }} | ||
+ | |||
+ | === Configuration === | ||
+ | Pour connaitre quels sont les fichiers de configuration qui sont lus, lancer la commande suivante : | ||
+ | msmtp --version | ||
+ | |||
+ | Exemple de retour : | ||
+ | {{terminal|text= | ||
+ | [root@myserver ~]# msmtp --version | ||
+ | msmtp version 1.8.10 | ||
+ | Plateforme : x86_64-redhat-linux-gnu | ||
+ | Librairie TLS/SSL : GnuTLS | ||
+ | Librairie d'authentification : GNU SASL; oauthbearer: built-in | ||
+ | Méthodes d'authentification supportées : | ||
+ | plain scram-sha-1 external gssapi cram-md5 digest-md5 login ntlm oauthbearer | ||
+ | Support IDN : désactivé | ||
+ | NLS: activé, LOCALEDIR : /usr/share/locale | ||
+ | Support de porte-clés: Gnome | ||
+ | Nom du fichier de configuration système : /etc/msmtprc | ||
+ | Nom du fichier de configuration utilisateur : /root/.msmtprc | ||
+ | |||
+ | Copyright (C) 2020 Martin Lambers and others. | ||
+ | This is free software. You may redistribute copies of it under the terms of | ||
+ | the GNU General Public License <http://www.gnu.org/licenses/gpl.html>. | ||
+ | There is NO WARRANTY, to the extent permitted by law. | ||
+ | }} | ||
+ | |||
+ | Dans cet exemple, le fichier de configuration global est <code>/etc/msmtprc</code> et le fichier de configuration de l'utilisateur est <code>$HOME/.msmtprc</code>. | ||
+ | |||
+ | En s'aidant de [https://marlam.de/msmtp/msmtp.html#A-system-wide-configuration-file la documentation officielle], on peut définir une configuration globale en adaptant cet exemple dans le fichier <code>/etc/msmtprc</code> : | ||
+ | <syntaxhighlight lang="python"> | ||
+ | # A system wide configuration file is optional. | ||
+ | # If it exists, it usually defines a default account. | ||
+ | # This allows msmtp to be used like /usr/sbin/sendmail. | ||
+ | account default | ||
+ | |||
+ | # The SMTP smarthost | ||
+ | host mail.oursite.example | ||
+ | |||
+ | # Use TLS on port 465 | ||
+ | port 465 | ||
+ | tls on | ||
+ | tls_starttls off | ||
+ | |||
+ | # Construct envelope-from addresses of the form "user@oursite.example" | ||
+ | from %U@oursite.example | ||
+ | |||
+ | # Syslog logging with facility LOG_MAIL instead of the default LOG_USER | ||
+ | syslog LOG_MAIL | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | Pour une configuration utilisateur, en s'aidant toujours de [https://marlam.de/msmtp/msmtp.html#A-user-configuration-file documentation officielle], on définir une configuration locale en adaptant cet exemple dans le fichier <code>$HOME/.msmtprc</code> : | ||
+ | <syntaxhighlight lang="python"> | ||
+ | # Example for a user configuration file ~/.msmtprc | ||
+ | # | ||
+ | # This file focusses on TLS and authentication. Features not used here include | ||
+ | # logging, timeouts, SOCKS proxies, TLS parameters, Delivery Status Notification | ||
+ | # (DSN) settings, and more. | ||
+ | |||
+ | |||
+ | # Set default values for all following accounts. | ||
+ | defaults | ||
+ | |||
+ | # Use the mail submission port 587 instead of the SMTP port 25. | ||
+ | port 587 | ||
+ | |||
+ | # Always use TLS. | ||
+ | tls on | ||
+ | |||
+ | # Set a list of trusted CAs for TLS. The default is to use system settings, but | ||
+ | # you can select your own file. | ||
+ | #tls_trust_file /etc/ssl/certs/ca-certificates.crt | ||
+ | # If you select your own file, you should also use the tls_crl_file command to | ||
+ | # check for revoked certificates, but unfortunately getting revocation lists and | ||
+ | # keeping them up to date is not straightforward. | ||
+ | #tls_crl_file ~/.tls-crls | ||
+ | |||
+ | |||
+ | # A freemail service | ||
+ | account freemail | ||
+ | |||
+ | # Host name of the SMTP server | ||
+ | host smtp.freemail.example | ||
+ | |||
+ | # As an alternative to tls_trust_file/tls_crl_file, you can use tls_fingerprint | ||
+ | # to pin a single certificate. You have to update the fingerprint when the | ||
+ | # server certificate changes, but an attacker cannot trick you into accepting | ||
+ | # a fraudulent certificate. Get the fingerprint with | ||
+ | # $ msmtp --serverinfo --tls --tls-certcheck=off --host=smtp.freemail.example | ||
+ | #tls_fingerprint 00:11:22:33:44:55:66:77:88:99:AA:BB:CC:DD:EE:FF:00:11:22:33 | ||
+ | |||
+ | # Envelope-from address | ||
+ | from joe_smith@freemail.example | ||
+ | |||
+ | # Authentication. The password is given using one of five methods, see below. | ||
+ | auth on | ||
+ | user joe.smith | ||
+ | |||
+ | # Password method 1: Add the password to the system keyring, and let msmtp get | ||
+ | # it automatically. To set the keyring password using Gnome's libsecret: | ||
+ | # $ secret-tool store --label=msmtp \ | ||
+ | # host smtp.freemail.example \ | ||
+ | # service smtp \ | ||
+ | # user joe.smith | ||
+ | |||
+ | # Password method 2: Store the password in an encrypted file, and tell msmtp | ||
+ | # which command to use to decrypt it. This is usually used with GnuPG, as in | ||
+ | # this example. Usually gpg-agent will ask once for the decryption password. | ||
+ | passwordeval gpg2 --no-tty -q -d ~/.msmtp-password.gpg | ||
+ | |||
+ | # Password method 3: Store the password directly in this file. Usually it is not | ||
+ | # a good idea to store passwords in cleartext files. If you do it anyway, at | ||
+ | # least make sure that this file can only be read by yourself. | ||
+ | #password secret123 | ||
+ | |||
+ | # Password method 4: Store the password in ~/.netrc. This method is probably not | ||
+ | # relevant anymore. | ||
+ | |||
+ | # Password method 5: Do not specify a password. Msmtp will then prompt you for | ||
+ | # it. This means you need to be able to type into a terminal when msmtp runs. | ||
+ | |||
+ | |||
+ | # A second mail address at the same freemail service | ||
+ | account freemail2 : freemail | ||
+ | from joey@freemail.example | ||
+ | |||
+ | |||
+ | # The SMTP server of your ISP | ||
+ | account isp | ||
+ | host mail.isp.example | ||
+ | from smithjoe@isp.example | ||
+ | auth on | ||
+ | user 12345 | ||
+ | |||
+ | |||
+ | # Set a default account | ||
+ | account default : freemail | ||
+ | </syntaxhighlight> |
Version actuelle datée du 25 mai 2020 à 16:41
Sommaire
Présentation
Cette page a pour objet de décrire comment installer MSMTP sur un serveur CentOS
Description
msmtp est un client SMTP très simple et facile à configurer pour l'envoi de courriels.
Son mode de fonctionnement par défaut consiste à transférer les courriels au serveur SMTP que vous aurez indiqué dans sa configuration. Ce dernier se chargera de distribuer les courriels à leurs destinataires.
Il est entièrement compatible avec sendmail, prend en charge le transport sécurisé TLS, les comptes multiples, diverses méthodes d’authentification et les notifications de distribution.
msmtp est la solution idéale si vous avez besoin que votre serveur vous envoie les courriels de notifications (taches Programmer des tâches avec CRON, Logwatch ou autre) sans avoir à mettre en place une solution lourde comme Postfix : agent de transfert de courriel (SMTP).
Plus d'informations sur https://marlam.de/msmtp/
Installation
Prérequis
Installer le dépôt EPEL :
yum -y install epel-release yum makecache
Installation du paquet msmtp
Installer le paquet msmtp avec la commande :
yum install msmtp
Exemple de retour :
[root@myserver ~]# yum install msmtp Modules complémentaires chargés : fastestmirror Loading mirror speeds from cached hostfile * base: fr2.rpmfind.net * epel: mirror.yandex.ru * extras: mirroir.wptheme.fr * updates: mirroir.wptheme.fr Résolution des dépendances --> Lancement de la transaction de test ---> Le paquet msmtp.x86_64 0:1.8.10-1.el7 sera installé --> Traitement de la dépendance : libgnutls.so.28(GNUTLS_1_4)(64bit) pour le paquet : msmtp-1.8.10-1.el7.x86_64 --> Traitement de la dépendance : libgnutls.so.28(GNUTLS_2_12)(64bit) pour le paquet : msmtp-1.8.10-1.el7.x86_64 --> Traitement de la dépendance : libgnutls.so.28(GNUTLS_3_0_0)(64bit) pour le paquet : msmtp-1.8.10-1.el7.x86_64 --> Traitement de la dépendance : libgnutls.so.28(GNUTLS_3_1_0)(64bit) pour le paquet : msmtp-1.8.10-1.el7.x86_64 --> Traitement de la dépendance : libgsasl.so.7(LIBGSASL_1.1)(64bit) pour le paquet : msmtp-1.8.10-1.el7.x86_64 --> Traitement de la dépendance : libgnutls.so.28()(64bit) pour le paquet : msmtp-1.8.10-1.el7.x86_64 --> Traitement de la dépendance : libgsasl.so.7()(64bit) pour le paquet : msmtp-1.8.10-1.el7.x86_64 --> Traitement de la dépendance : libsecret-1.so.0()(64bit) pour le paquet : msmtp-1.8.10-1.el7.x86_64 --> Lancement de la transaction de test ---> Le paquet gnutls.x86_64 0:3.3.29-9.el7_6 sera installé --> Traitement de la dépendance : trousers >= 0.3.11.2 pour le paquet : gnutls-3.3.29-9.el7_6.x86_64 --> Traitement de la dépendance : libnettle.so.4()(64bit) pour le paquet : gnutls-3.3.29-9.el7_6.x86_64 --> Traitement de la dépendance : libhogweed.so.2()(64bit) pour le paquet : gnutls-3.3.29-9.el7_6.x86_64 ---> Le paquet libgsasl.x86_64 0:1.8.0-8.el7 sera installé --> Traitement de la dépendance : libntlm.so.0()(64bit) pour le paquet : libgsasl-1.8.0-8.el7.x86_64 ---> Le paquet libsecret.x86_64 0:0.18.6-1.el7 sera installé --> Lancement de la transaction de test ---> Le paquet libntlm.x86_64 0:1.3-6.el7 sera installé ---> Le paquet nettle.x86_64 0:2.7.1-8.el7 sera installé ---> Le paquet trousers.x86_64 0:0.3.14-2.el7 sera installé --> Résolution des dépendances terminée Dépendances résolues ============================================================================================================================================================================================================================================== Package Architecture Version Dépôt Taille ============================================================================================================================================================================================================================================== Installation : msmtp x86_64 1.8.10-1.el7 epel 174 k Installation pour dépendances : gnutls x86_64 3.3.29-9.el7_6 base 680 k libgsasl x86_64 1.8.0-8.el7 epel 131 k libntlm x86_64 1.3-6.el7 base 44 k libsecret x86_64 0.18.6-1.el7 base 153 k nettle x86_64 2.7.1-8.el7 base 327 k trousers x86_64 0.3.14-2.el7 base 289 k Résumé de la transaction ============================================================================================================================================================================================================================================== Installation 1 Paquet (+6 Paquets en dépendance) Taille totale des téléchargements : 1.8 M Taille d'installation : 5.0 M Is this ok [y/d/N]: y Downloading packages: (1/7): libntlm-1.3-6.el7.x86_64.rpm | 44 kB 00:00:00 (2/7): libsecret-0.18.6-1.el7.x86_64.rpm | 153 kB 00:00:00 (3/7): gnutls-3.3.29-9.el7_6.x86_64.rpm | 680 kB 00:00:00 warning: /var/cache/yum/x86_64/7/epel/packages/libgsasl-1.8.0-8.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID 352c64e5: NOKEY La clé publique pour libgsasl-1.8.0-8.el7.x86_64.rpm n'est pas installée (4/7): libgsasl-1.8.0-8.el7.x86_64.rpm | 131 kB 00:00:00 (5/7): msmtp-1.8.10-1.el7.x86_64.rpm | 174 kB 00:00:00 (6/7): nettle-2.7.1-8.el7.x86_64.rpm | 327 kB 00:00:00 (7/7): trousers-0.3.14-2.el7.x86_64.rpm | 289 kB 00:00:00
Total 3.0 MB/s | 1.8 MB 00:00:00 Récupération de la clé à partir de file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7 Importation de la clef GPG 0x352C64E5 : ID utilisateur : « Fedora EPEL (7) <epel@fedoraproject.org> » Empreinte : 91e9 7d7c 4a5e 96f1 7f3e 888f 6a2f aea2 352c 64e5 Paquet : epel-release-7-11.noarch (@extras) Provient de : /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7 Est-ce correct [o/N] : o Running transaction check Running transaction test Transaction test succeeded Running transaction Installation : nettle-2.7.1-8.el7.x86_64 1/7 Installation : libsecret-0.18.6-1.el7.x86_64 2/7 Installation : libntlm-1.3-6.el7.x86_64 3/7 Installation : libgsasl-1.8.0-8.el7.x86_64 4/7 Installation : trousers-0.3.14-2.el7.x86_64 5/7 Installation : gnutls-3.3.29-9.el7_6.x86_64 6/7 Installation : msmtp-1.8.10-1.el7.x86_64 7/7 Vérification : trousers-0.3.14-2.el7.x86_64 1/7 Vérification : msmtp-1.8.10-1.el7.x86_64 2/7 Vérification : libntlm-1.3-6.el7.x86_64 3/7 Vérification : libgsasl-1.8.0-8.el7.x86_64 4/7 Vérification : libsecret-0.18.6-1.el7.x86_64 5/7 Vérification : nettle-2.7.1-8.el7.x86_64 6/7 Vérification : gnutls-3.3.29-9.el7_6.x86_64 7/7 Installé : msmtp.x86_64 0:1.8.10-1.el7 Dépendances installées : gnutls.x86_64 0:3.3.29-9.el7_6 libgsasl.x86_64 0:1.8.0-8.el7 libntlm.x86_64 0:1.3-6.el7 libsecret.x86_64 0:0.18.6-1.el7 nettle.x86_64 0:2.7.1-8.el7 trousers.x86_64 0:0.3.14-2.el7 Terminé !
Configuration
Pour connaitre quels sont les fichiers de configuration qui sont lus, lancer la commande suivante :
msmtp --version
Exemple de retour :
[root@myserver ~]# msmtp --version msmtp version 1.8.10 Plateforme : x86_64-redhat-linux-gnu Librairie TLS/SSL : GnuTLS Librairie d'authentification : GNU SASL; oauthbearer: built-in Méthodes d'authentification supportées : plain scram-sha-1 external gssapi cram-md5 digest-md5 login ntlm oauthbearer Support IDN : désactivé NLS: activé, LOCALEDIR : /usr/share/locale Support de porte-clés: Gnome Nom du fichier de configuration système : /etc/msmtprc Nom du fichier de configuration utilisateur : /root/.msmtprc Copyright (C) 2020 Martin Lambers and others. This is free software. You may redistribute copies of it under the terms of the GNU General Public License <http://www.gnu.org/licenses/gpl.html>. There is NO WARRANTY, to the extent permitted by law.
Dans cet exemple, le fichier de configuration global est /etc/msmtprc
et le fichier de configuration de l'utilisateur est $HOME/.msmtprc
.
En s'aidant de la documentation officielle, on peut définir une configuration globale en adaptant cet exemple dans le fichier /etc/msmtprc
:
# A system wide configuration file is optional.
# If it exists, it usually defines a default account.
# This allows msmtp to be used like /usr/sbin/sendmail.
account default
# The SMTP smarthost
host mail.oursite.example
# Use TLS on port 465
port 465
tls on
tls_starttls off
# Construct envelope-from addresses of the form "user@oursite.example"
from %U@oursite.example
# Syslog logging with facility LOG_MAIL instead of the default LOG_USER
syslog LOG_MAIL
Pour une configuration utilisateur, en s'aidant toujours de documentation officielle, on définir une configuration locale en adaptant cet exemple dans le fichier $HOME/.msmtprc
:
# Example for a user configuration file ~/.msmtprc
#
# This file focusses on TLS and authentication. Features not used here include
# logging, timeouts, SOCKS proxies, TLS parameters, Delivery Status Notification
# (DSN) settings, and more.
# Set default values for all following accounts.
defaults
# Use the mail submission port 587 instead of the SMTP port 25.
port 587
# Always use TLS.
tls on
# Set a list of trusted CAs for TLS. The default is to use system settings, but
# you can select your own file.
#tls_trust_file /etc/ssl/certs/ca-certificates.crt
# If you select your own file, you should also use the tls_crl_file command to
# check for revoked certificates, but unfortunately getting revocation lists and
# keeping them up to date is not straightforward.
#tls_crl_file ~/.tls-crls
# A freemail service
account freemail
# Host name of the SMTP server
host smtp.freemail.example
# As an alternative to tls_trust_file/tls_crl_file, you can use tls_fingerprint
# to pin a single certificate. You have to update the fingerprint when the
# server certificate changes, but an attacker cannot trick you into accepting
# a fraudulent certificate. Get the fingerprint with
# $ msmtp --serverinfo --tls --tls-certcheck=off --host=smtp.freemail.example
#tls_fingerprint 00:11:22:33:44:55:66:77:88:99:AA:BB:CC:DD:EE:FF:00:11:22:33
# Envelope-from address
from joe_smith@freemail.example
# Authentication. The password is given using one of five methods, see below.
auth on
user joe.smith
# Password method 1: Add the password to the system keyring, and let msmtp get
# it automatically. To set the keyring password using Gnome's libsecret:
# $ secret-tool store --label=msmtp \
# host smtp.freemail.example \
# service smtp \
# user joe.smith
# Password method 2: Store the password in an encrypted file, and tell msmtp
# which command to use to decrypt it. This is usually used with GnuPG, as in
# this example. Usually gpg-agent will ask once for the decryption password.
passwordeval gpg2 --no-tty -q -d ~/.msmtp-password.gpg
# Password method 3: Store the password directly in this file. Usually it is not
# a good idea to store passwords in cleartext files. If you do it anyway, at
# least make sure that this file can only be read by yourself.
#password secret123
# Password method 4: Store the password in ~/.netrc. This method is probably not
# relevant anymore.
# Password method 5: Do not specify a password. Msmtp will then prompt you for
# it. This means you need to be able to type into a terminal when msmtp runs.
# A second mail address at the same freemail service
account freemail2 : freemail
from joey@freemail.example
# The SMTP server of your ISP
account isp
host mail.isp.example
from smithjoe@isp.example
auth on
user 12345
# Set a default account
account default : freemail