Installation de MailHog et connexion avec Wordpress
Distribution de travail : Ubuntu 20.04
Liens : https://kinsta.com/fr/blog/mailhog/ https://www.lullabot.com/articles/installing-mailhog-for-ubuntu-1604
Installation de GoLang.
samuelg@optiplex:~$ sudo apt-get -y install golang-go
Répertoire de travail.
samuelg@optiplex:~$ mkdir MAILHOG
samuelg@optiplex:~$ cd MAILHOG/
samuelg@optiplex:~/MAILHOG$
Installation de MailHog.
samuelg@optiplex:~/MAILHOG$ go get github.com/mailhog/MailHog samuelg@optiplex:~/MAILHOG$ go get github.com/mailhog/mhsendmail
Vérification.
samuelg@optiplex:~/MAILHOG$ ls -l ~/go/bin/
total 18784
-rwxrwxr-x 1 samuelg samuelg 13514285 sep 8 09:54 MailHog
-rwxrwxr-x 1 samuelg samuelg 5717844 sep 8 09:52 mhsendmail
Installation.
samuelg@optiplex:~/MAILHOG$ sudo cp ~/go/bin/MailHog /usr/local/bin/mailhog
samuelg@optiplex:~/MAILHOG$ sudo cp ~/go/bin/mhsendmail /usr/local/bin/
Lancement de MailHog.
samuelg@optiplex:~/MAILHOG$ mailhog \
-api-bind-addr 127.0.0.1:8025 \
-ui-bind-addr 127.0.0.1:8025 \
-smtp-bind-addr 127.0.0.1:1025
Adresse SMTP local : localhost Port SMTP local : 1025
Interface graphique.
http://localhost:8025/
Configuration de PHP.
Ouvrir :
/etc/php/7.4/apache2/php.ini
Chercher :
;sendmail_path =
Remplacer par :
sendmail_path = /usr/local/bin/mhsendmail
Ouvrir :
/etc/php/7.4/cli/php.ini
Chercher :
;sendmail_path =
Remplacer par :
sendmail_path = /usr/local/bin/mhsendmail
Test en ligne de commande.
$ mhsendmail test@mailhog.local <<EOF
From: Samuel <contact@monsite.local>
To: Test <test@mailhoga.local>
Subject: Hello, MailHog!
Bonjour à tous !
Sam
EOF
Test en PHP.
- Script :
Créer :
sendMail.php
Ajouter :
<?php
$to = "test@mailhog.local";
$subject = "Hey, I’m Pi Hog Pi!";
$body = "Hello, MailHog!";
$headers = "From: pihogpi@kinsta.com" . "\r\n";
mail($to,$subject,$body,$headers);
?>
- Envoi de mail :
$ php ./sendMail.php
Test avec Wordpress.
- Installation de l'extension 'WP Mail SMTP' :
https://wordpress.org/plugins/wp-mail-smtp/
-
Configuration :
- [WP Mail SMTP] [Général]
- [Service d’envoi] : Autre SMTP
- Hébergeur SMTP : localhost
Cryptage : Aucun
Port SMTP : 1025
TLS auto : ACTIVÉ
Authentification : DÉSACTIVÉ - [Enregistrer les réglages]
-
Test :
- [E-mail de test]
- Envoyer à : gondouin@h2a.lu
[Envoyer l'email]