07Mail - amagerard/TemplateVM GitHub Wiki

HOME

RedHat/TemplateVM.

1- Installation 2- Network 3- Firewall 4- Selinux
5- Logs 6- Certificates 7- Mail 8- PassphraseSSH
9- Sudo 10- GnomeShell 11- CloneVM 12- Volume
13- Troubleshoot

7. Mail alert.

It means receiving alert messages by email on malfunctions
detected on the server.

7.1 msmtp.

It no longer works with gmail, gmx etc...
We need an email provider that allows passwordeval.
I couldn't find a solution to hide the decryption password.
It is no longer possible with authentication OAuth2.
My internet service provider allows me this solution.

Prerequisites:

  • Provider smtp server.
  • SMTP server port.
  • The identifiers of the email account at the provider.
  • Example:
    email address: [email protected]
    password: 6hj9lmbGtr
    user: [email protected]
    provider: googl.com
    smtp: smtp.googl.com
    port: 587

7.2 configuration msmtp.

7.2.1 Install messaging software.

dnf install msmtp
Copy the msmtprc-user.example file.
cp /usr/share/doc/msmtp/msmtprc-user.example /etc/msmtprc

7.2.2 Configuration for the email password.

Generate an identity with gpg.
Create a folder to drop the files into.
mkdir /root/.dove
Create a file to put the password of your email account.
vi /root/.dove/msmtp-password

 6hj9lmbGtr  

Encrypt the /root/.dove/msmtp-password file.
gpg -c --cipher-algo AES256 /root/.dove/msmtp-password
Remember the passphrase.
This command creates a /root/.dove/msmtp-password.gpg file.
Create a txt file to put the passphrase.
touch /root/.dove/file.txt
Example the passphrase is 'Therighttimeistoarrive'
vi /root/.dove/file.txt

Therighttimeistoarrive  

Check your email password.
gpg2 --batch --passphrase-file /root/.dove/file.txt --quiet --for-your-eyes-only --no-tty --decrypt /root/.dove/msmtp-password.gpg

7.2.3 Configuration for your mail provider.

Edit file:
vi /etc/msmtprc

#modify or add  
defaults  
port 587  
tls on  
tls_starttls on  
# Define a mail account at a freemail service  
account googl.com  
# Host name of the SMTP server  
host  smtp.googl.com  
# Envelope-from address  
from [email protected]  
# Authentication  
auth on  
user [email protected]  
# this example. Usually gpg-agent will ask once for the decryption password.  
passwordeval  "gpg2  --batch --passphrase-file /root/.dove/file.txt --quiet --for-your-eyes-only  --no-tty --decrypt /root/.dove/msmtp-password.gpg"  
# and just changes the envelope from address  
#account freemail2 : freemail  
#from [email protected]  
# Some other mail service  
#account company  
#host mail.company.example  
#from [email protected]  
#auth on  
#user company12345  
# Set a default account  
account default : googl.com  
  

Put restrictions on /root/.dove.
chmod -R 600 /root/.dove
Put restrictions on /etc/msmtprc.
chmod 600 /etc/msmtprc

7.2.4 Test

Example.
You write a mail for your mother: [email protected].
echo -e "Subject: Hi, I'm here " | msmtp -t [email protected]