Différences
Ci-dessous, les différences entre deux révisions de la page.
| Les deux révisions précédentes Révision précédente Prochaine révision | Révision précédente | ||
| eadl:bloc3:dev_av:td4 [2025/11/09 23:20] – [7.4 Test] jcheron | eadl:bloc3:dev_av:td4 [2025/11/10 16:28] (Version actuelle) – [Concepts clés à retenir] jcheron | ||
|---|---|---|---|
| Ligne 1306: | Ligne 1306: | ||
| < | < | ||
| - | ===== Partie 7 : Visualiser les emails avec MailHog | + | ===== Partie 7 : Visualiser les emails avec MailPit |
| <WRAP round bloc info> | <WRAP round bloc info> | ||
| - | **MailHog** = Serveur SMTP factice | + | **Mailpit** = Serveur SMTP de test avec interface web moderne |
| - | * Pas de configuration SMTP réelle | + | * Capture tous les emails envoyés par l' |
| - | * Interface web pour voir tous les emails | + | * Interface web pour visualiser |
| - | * Pas de risque d' | + | * Aucune configuration SMTP complexe |
| + | * Parfait pour le développement | ||
| </ | </ | ||
| - | ==== 7.1 Ajouter | + | ==== 7.1 Ajouter |
| + | |||
| + | Ajouter ce service dans votre fichier **'' | ||
| <sxh yaml> | <sxh yaml> | ||
| - | | + | |
| - | image: | + | image: |
| - | container_name: | + | container_name: |
| ports: | ports: | ||
| - " | - " | ||
| Ligne 1326: | Ligne 1329: | ||
| networks: | networks: | ||
| - ecommerce-network | - ecommerce-network | ||
| + | </ | ||
| + | |||
| + | <sxh bash> | ||
| + | # Démarrer Mailpit | ||
| + | docker-compose up -d mailpit | ||
| + | |||
| + | # Vérifier que Mailpit est démarré | ||
| + | docker ps | grep mailpit | ||
| </ | </ | ||
| ==== 7.2 Configuration Spring ==== | ==== 7.2 Configuration Spring ==== | ||
| - | Modifier **'' | + | Modifier |
| <sxh properties> | <sxh properties> | ||
| - | # MailHog | + | # Mailpit configuration |
| spring.mail.host=localhost | spring.mail.host=localhost | ||
| spring.mail.port=1025 | spring.mail.port=1025 | ||
| Ligne 1341: | Ligne 1352: | ||
| spring.mail.properties.mail.smtp.starttls.enable=false | spring.mail.properties.mail.smtp.starttls.enable=false | ||
| + | # Notification settings | ||
| notification.email.enabled=true | notification.email.enabled=true | ||
| notification.email.from=noreply@ecommerce-demo.com | notification.email.from=noreply@ecommerce-demo.com | ||
| Ligne 1346: | Ligne 1358: | ||
| # Logs pour voir les envois | # Logs pour voir les envois | ||
| logging.level.org.springframework.mail=DEBUG | logging.level.org.springframework.mail=DEBUG | ||
| + | </ | ||
| + | |||
| + | Modifier également **'' | ||
| + | |||
| + | <sxh properties> | ||
| + | # Mailpit pour les tests | ||
| + | spring.mail.host=localhost | ||
| + | spring.mail.port=1025 | ||
| + | |||
| + | notification.email.enabled=true | ||
| + | notification.email.from=test@ecommerce-demo.com | ||
| </ | </ | ||
| ==== 7.3 Améliorer les logs dans EmailNotificationSender ==== | ==== 7.3 Améliorer les logs dans EmailNotificationSender ==== | ||
| + | |||
| + | Modifier la méthode **'' | ||
| <sxh kotlin> | <sxh kotlin> | ||
| Ligne 1363: | Ligne 1388: | ||
| mailSender.send(message) | mailSender.send(message) | ||
| | | ||
| - | logger.info(" | + | logger.info(" |
| - | logger.debug(" | + | logger.info(" |
| | | ||
| } catch (e: Exception) { | } catch (e: Exception) { | ||
| - | logger.error(" | + | logger.error(" |
| throw RuntimeException(" | throw RuntimeException(" | ||
| } | } | ||
| Ligne 1373: | Ligne 1398: | ||
| </ | </ | ||
| - | ==== 7.4 Test ==== | + | ==== 7.4 Test manuel |
| <sxh bash> | <sxh bash> | ||
| - | # 1. Démarrer | + | # 1. Démarrer |
| - | docker-compose up -d mailhog | + | docker-compose up -d mailpit |
| # 2. Lancer l' | # 2. Lancer l' | ||
| mvn spring-boot: | mvn spring-boot: | ||
| - | # 3. Créer une commande | + | # 3. Créer une commande |
| curl -X POST http:// | curl -X POST http:// | ||
| -H " | -H " | ||
| Ligne 1388: | Ligne 1413: | ||
| " | " | ||
| " | " | ||
| - | " | + | " |
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| }' | }' | ||
| - | # 4. Ouvrir | + | # 7.4 Ouvrir |
| open http:// | open http:// | ||
| + | # Ou dans votre navigateur : http:// | ||
| </ | </ | ||
| <WRAP round bloc todo> | <WRAP round bloc todo> | ||
| - | **Résultat attendu | + | **Vérifications à effectuer |
| - | | + | |
| - | | + | |
| - | | + | |
| + | 4. Vérifier que le contenu HTML est correct | ||
| + | 5. Vérifier le sujet : "Order Confirmation # | ||
| + | | ||
| </ | </ | ||
| + | |||
| + | ==== 7.5 Interface Mailpit ==== | ||
| + | |||
| + | L' | ||
| + | * Voir tous les emails envoyés | ||
| + | * Rechercher dans les emails | ||
| + | * Prévisualiser le HTML et le texte brut | ||
| + | * Voir les pièces jointes | ||
| + | * Supprimer les emails | ||
| + | * Tester le responsive design des emails | ||
| + | |||
| + | ==== 7.6 Configuration pour la production ==== | ||
| <WRAP round bloc important> | <WRAP round bloc important> | ||
| - | **Production vs Développement :** | + | ** Mailpit est uniquement pour le développement !** |
| - | En **développement** (MailHog) : | + | En **développement** (Mailpit) : |
| - | <code properties> | + | <sxh properties> |
| spring.mail.host=localhost | spring.mail.host=localhost | ||
| spring.mail.port=1025 | spring.mail.port=1025 | ||
| - | </code> | + | notification.email.enabled=true |
| + | </sxh> | ||
| - | En **production** (SMTP réel) : | + | En **production** (SMTP réel - exemple avec Gmail) : |
| - | <code properties> | + | <sxh properties> |
| spring.mail.host=smtp.gmail.com | spring.mail.host=smtp.gmail.com | ||
| spring.mail.port=587 | spring.mail.port=587 | ||
| Ligne 1419: | Ligne 1467: | ||
| spring.mail.properties.mail.smtp.auth=true | spring.mail.properties.mail.smtp.auth=true | ||
| spring.mail.properties.mail.smtp.starttls.enable=true | spring.mail.properties.mail.smtp.starttls.enable=true | ||
| - | </ | ||
| - | ⚠️ | + | notification.email.enabled=true |
| + | notification.email.from=${EMAIL_FROM} | ||
| + | </ | ||
| + | |||
| + | ** Bonnes pratiques :** | ||
| + | | ||
| + | * Utiliser des **variables d' | ||
| + | * Activer **TLS/SSL** en production | ||
| + | * Utiliser des **app passwords** (Gmail, Outlook, etc.) | ||
| </ | </ | ||
| + | |||
| + | ==== 7.7 Commandes utiles ==== | ||
| + | |||
| + | <sxh bash> | ||
| + | # Démarrer uniquement Mailpit | ||
| + | docker-compose up -d mailpit | ||
| + | |||
| + | # Voir les logs de Mailpit | ||
| + | docker logs -f ecommerce-mailpit | ||
| + | |||
| + | # Redémarrer Mailpit | ||
| + | docker-compose restart mailpit | ||
| + | |||
| + | # Arrêter Mailpit | ||
| + | docker-compose stop mailpit | ||
| + | |||
| + | # Supprimer le conteneur Mailpit | ||
| + | docker-compose down mailpit | ||
| + | </ | ||
| + | |||
| + | ==== 7.8 Dépannage ==== | ||
| + | |||
| + | **Problème : Les emails n' | ||
| + | |||
| + | <sxh bash> | ||
| + | # 1. Vérifier que Mailpit est démarré | ||
| + | docker ps | grep mailpit | ||
| + | |||
| + | # 2. Vérifier les logs de l' | ||
| + | # Rechercher : "Email sent to:" ou " | ||
| + | |||
| + | # 3. Vérifier que le profil dev est actif | ||
| + | # Dans les logs au démarrage : "The following profiles are active: dev" | ||
| + | |||
| + | # 4. Tester la connexion SMTP | ||
| + | telnet localhost 1025 | ||
| + | </ | ||
| + | |||
| + | **Problème : " | ||
| + | |||
| + | < | ||
| + | # Vérifier que le port 1025 n'est pas déjà utilisé | ||
| + | lsof -i :1025 | ||
| + | |||
| + | # Si occupé, changer le port dans docker-compose.yml et application-dev.properties | ||
| + | </ | ||
| + | |||
| + | |||
| + | |||
| + | |||
| + | |||
| ===== Livrables attendus ===== | ===== Livrables attendus ===== | ||
| Ligne 1458: | Ligne 1564: | ||
| * Ajout du canal SMS | * Ajout du canal SMS | ||
| - | * Template d' | + | * Template d' |
| * Retry automatique en cas d' | * Retry automatique en cas d' | ||
| * Dashboard des notifications dans H2 console | * Dashboard des notifications dans H2 console | ||
| Ligne 1471: | Ligne 1577: | ||
| * **Observer** : Spring Events pour la communication inter-domaines | * **Observer** : Spring Events pour la communication inter-domaines | ||
| * **Strategy** : '' | * **Strategy** : '' | ||
| - | * **Factory** : Injection automatique de tous les senders | + | * **Factory** : Injection automatique de tous les senders |
| * **Dependency Inversion** : '' | * **Dependency Inversion** : '' | ||