MSMTP

De Wiki de Jordan LE NUFF
Sauter à la navigation Sauter à la recherche

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 :

Putty icon.png Console SSH

Configuration

Pour connaitre quels sont les fichiers de configuration qui sont lus, lancer la commande suivante :

msmtp --version

Exemple de retour :

Putty icon.png Console SSH

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