Web Reporting with Sendmail

Comment mettre en place, l’envoi de mail, de reporting serveur via le protocole smtp.

 

Le protocole SMTP ( entendez : Simple Mail Transfer Protocol ), vous permet de mettre en place sendmail de la manière la plus simple possible. Sendmail étant ressenti comme un logiciel difficile à administrer !

Si vous êtes fidèle au noyau Linux, vous disposez certainement d’un compte gmail depuis le rachat d’Android par Google, il est extrêmement simple de le mettre en oeuvre. Je décris içi l’installation sous Gentoo…

Téléchargeons ssmtp depuis portage :

pingwho ~ # emerge -av ssmtp

 * IMPORTANT: 17 news items need reading for repository 'gentoo'.
 * Use eselect news read to view new items.

These are the packages that would be merged, in order:

Calculating dependencies... done!
[ebuild   R    ] mail-mta/ssmtp-2.64-r2::gentoo  USE="gnutls ipv6 mta ssl" 0 KiB

Total: 1 package (1 reinstall), Size of downloads: 0 KiB

Would you like to merge these packages? [Yes/No]

Configurons ssmtp.conf pour Gmail :

pingwho ssmtp # cat /etc/ssmtp/ssmtp.conf
#
# /etc/ssmtp.conf -- a config file for sSMTP sendmail.
#

# The person who gets all mail for userids < MinUserId # Make this empty to disable rewriting. #root=postmaster # All mail delivered to userid >= MinUserId goes to user, not root.
#MinUserId=1000

# The place where the mail goes. The actual machine name is required
# no MX records are consulted. Commonly mailhosts are named mail.domain.com
# The example will fit if you are in domain.com and your mailhub is so named.
#mailhub=mail

# Example for SMTP port number 2525
# mailhub=mail.your.domain:2525
# Example for SMTP port number 25 (Standard/RFC)
# mailhub=mail.your.domain
# Example for SSL encrypted connection
# mailhub=mail.your.domain:465

# Where will the mail seem to come from?
#rewriteDomain=

# The full hostname

# Gentoo bug #47562
# Commenting the following line will force ssmtp to figure
# out the hostname itself.

# hostname=_HOSTNAME_

# Set this to never rewrite the "From:" line (unless not given) and to
# use that address in the "from line" of the envelope.
#FromLineOverride=YES

# Use SSL/TLS to send secure messages to server.
#UseTLS=YES

# Use SSL/TLS certificate to authenticate against smtp host.
#UseTLSCert=YES

# Use this RSA certificate.
#TLSCert=/etc/ssl/certs/ssmtp.pem

# Get enhanced (*really* enhanced) debugging information in the logs
# If you want to have debugging of the config file parsing, move this option
# to the top of the config file and uncomment
Debug=YES

# Port 587 via TLS just encrypt password

#root=
#rewriteDomain=
#hostname=localhost
#AuthMethod=CRAM-MD5 (not supported !)
AuthUser=user
AuthPass=password
mailhub=smtp.gmail.com:587
UseSTARTTLS=YES
UseTLS=YES
FromLineOverride=YES

# Port 465 SSL/TLS full encrypt session (deprecated)
#root=root@localhost
#AuthUser=user
#AuthPass=passord
#mailhub=smtp.gmail.com:465
#UseTLS=YES
#rewriteDomain=domain.org
#FromLineOverride=YES
#hostnamelocalhost

Configuration des alias mail :

# sSMTP aliases
#
# Format:       local_account:outgoing_address:mailhub
#
# Example: root:your_login@your.domain:mailhub.your.domain[:port]
# where [:port] is an optional port number that defaults to 25.

# port 587 TLS encrypt password only
root:username@gmail.com:smtp.gmail.com:587

Installation de mailx :

pingwho grsec # emerge -av mailx

 * IMPORTANT: 17 news items need reading for repository 'gentoo'.
 * Use eselect news read to view new items.


These are the packages that would be merged, in order:

Calculating dependencies... done!
[ebuild   R    ] mail-client/mailx-8.1.2.20050715-r6::gentoo  0 KiB

Total: 1 package (1 reinstall), Size of downloads: 0 KiB

Would you like to merge these packages? [Yes/No]

Envoi d’un mail en BASH :

echo "Hello World !" | mail -v -s "Test sendmail" root@localhost

Vous disposez maintenant d’un serveur sendmail pour router vos mails système via gmail.com mode TLS security

Mon avis : Un couteau suisse bien affuté, mais il manque encore de maturité, car le mot de passe est inscrit en clair dans /etc, ce qui en soi n’est pas propre du tout !

Je l’utilise régulièrement pour logguer mes tâches cron, ça fonctionne très bien soit « dît » en passant !

enjoy :,)