ssmtp – envoyer des mail en ligne de commande
|
On met le système à jour avec la commande:sudo apt-get update && sudo apt-get upgrade -y
On Install ssmtp avec la commande:
sudo apt-get install ssmtp
On Install aussi mailutils qui permettra d’envoyé des mail avec la commande mail:sudo apt install mailutils
On va définir les serveurs SMTP dans le fichier de configuration SSMTP:sudo nano /etc/ssmtp/ssmtp.conf
#
# Config file for sSMTP sendmail
#
# The person who gets all mail for userids < 1000
# Make this empty to disable rewriting.
root=Your@MailServer.com
# The place where the mail goes. The actual machine name is required no
# MX records are consulted. Commonly mailhosts are named mail.domain.com
mailhub=smtp.MailServer.com:587
# Where will the mail seem to come from?
#rewriteDomain=
# The full hostname
hostname=MailServer.com
# Are users allowed to set their own From: address?
# YES - Allow the user to specify their own From: address
# NO - Use the system generated From: address
FromLineOverride=YES
# Username and password for Google's Gmail servers
# From addresses are settled by Mutt's rc file, so
# with this setup one can still achieve multi-user SMTP
AuthUser=Your@MailServer.com
AuthPass=Your@MailServer.com-Password
AuthMethod=LOGIN
FromLineOverride=YES
UseSTARTTLS=YES
On va créer un fichier test avec la commande:sudo echo "Salut, Ceci est un fichier teste!" >> test.txt
On envois un mail test avec la commande:ssmtp -v Your@MailServer.com < test.txt
Quelque chose de similaire devrait s’afficher:
[<-] 220 smtp-1.smtp.MailServer.com ESMTP
[->] EHLO smtp.MailServer.com
[<-] 250 8BITMIME
[->] STARTTLS
[<-] 220 2.0.0 Ready to start TLS
[->] EHLO smtp.MailServer.com
[<-] 250 8BITMIME
[->] AUTH LOGIN
[<-] 334 xxxxxxxxxxxxxxx
[->] xxxxxxxxxxxxxx
[<-] 334 xxxxxxxxxxxxxxxxx
[<-] 235 2.7.0 Authentication successful
[->] MAIL FROM:<YourServerOrVPS@smtp.MailServer.com>
[<-] 250 2.1.0 Ok
[->] RCPT TO:<YourRecption@MailServer.com>
[<-] 250 2.1.5 Ok
[->] DATA
[<-] 354 End data with <CR><LF>.<CR><LF>
[->] Received: by pt.lu (sSMTP sendmail emulation); Wed, 15 Jun 2022 12:57:13 +0200
[->] From: YourServerOrVPS@smtp.MailServer.com
[->] Date: Wed, 15 Jun 2022 12:57:13 +0200
[->] Salut, Ceci est un fichier teste!
[->]
[->] .
[<-] 250 2.0.0 Ok: queued as xxxxxxxxxxxxx
[->] QUIT
[<-] 221 2.0.0 Bye
On contrôle notre boite mail si le mail est bien arriver.
mes sources: https://www.atlantic.net/vps-hosting/how-to-use-ssmtp-to-send-an-email-from-linux-terminal/
https://unix.stackexchange.com/questions/359880/problem-sending-email-using-ssmtp
https://www.delftstack.com/fr/howto/linux/how-to-create-a-file-in-linux-terminal/
https://www.linuxtricks.fr/wiki/print.php?id=752
https://fr.linux-console.net/?p=796#gsc.tab=0