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/10 07:12] – [7.4 Test manuel] jcheron | eadl:bloc3:dev_av:td4 [2025/11/10 16:28] (Version actuelle) – [Concepts clés à retenir] jcheron | ||
|---|---|---|---|
| Ligne 1310: | Ligne 1310: | ||
| <WRAP round bloc info> | <WRAP round bloc info> | ||
| **Mailpit** = Serveur SMTP de test avec interface web moderne | **Mailpit** = Serveur SMTP de test avec interface web moderne | ||
| - | * ✅ Capture tous les emails envoyés par l' | + | * Capture tous les emails envoyés par l' |
| - | * ✅ Interface web pour visualiser les emails | + | * Interface web pour visualiser les emails |
| - | * ✅ Aucune configuration SMTP complexe | + | * Aucune configuration SMTP complexe |
| - | * ✅ Parfait pour le développement | + | * Parfait pour le développement |
| </ | </ | ||
| Ligne 1450: | Ligne 1450: | ||
| <WRAP round bloc important> | <WRAP round bloc important> | ||
| - | **⚠️ | + | ** Mailpit est uniquement pour le développement !** |
| En **développement** (Mailpit) : | En **développement** (Mailpit) : | ||
| Ligne 1472: | Ligne 1472: | ||
| </ | </ | ||
| - | **🔐 Bonnes pratiques :** | + | ** Bonnes pratiques :** |
| * Ne **jamais** commiter les credentials SMTP dans le code | * Ne **jamais** commiter les credentials SMTP dans le code | ||
| * Utiliser des **variables d' | * Utiliser des **variables d' | ||
| Ligne 1498: | Ligne 1498: | ||
| </ | </ | ||
| - | ==== 8. Dépannage ==== | + | ==== 7.8 Dépannage ==== |
| **Problème : Les emails n' | **Problème : Les emails n' | ||
| Ligne 1525: | Ligne 1525: | ||
| </ | </ | ||
| - | ==== 7.1 Ajouter MailHog au docker-compose.yml ==== | ||
| - | <sxh yaml> | ||
| - | mailhog: | ||
| - | image: mailhog/ | ||
| - | container_name: | ||
| - | ports: | ||
| - | - " | ||
| - | - " | ||
| - | networks: | ||
| - | - ecommerce-network | ||
| - | </ | ||
| - | ==== 7.2 Configuration Spring ==== | ||
| - | Modifier **'' | ||
| - | <sxh properties> | ||
| - | # MailHog | ||
| - | spring.mail.host=localhost | ||
| - | spring.mail.port=1025 | ||
| - | spring.mail.username= | ||
| - | spring.mail.password= | ||
| - | spring.mail.properties.mail.smtp.auth=false | ||
| - | spring.mail.properties.mail.smtp.starttls.enable=false | ||
| - | |||
| - | notification.email.enabled=true | ||
| - | notification.email.from=noreply@ecommerce-demo.com | ||
| - | |||
| - | # Logs pour voir les envois | ||
| - | logging.level.org.springframework.mail=DEBUG | ||
| - | </ | ||
| - | |||
| - | ==== 7.3 Améliorer les logs dans EmailNotificationSender ==== | ||
| - | |||
| - | <sxh kotlin> | ||
| - | override fun send(recipient: | ||
| - | try { | ||
| - | val message = mailSender.createMimeMessage() | ||
| - | val helper = MimeMessageHelper(message, | ||
| - | | ||
| - | helper.setFrom(fromEmail) | ||
| - | helper.setTo(recipient) | ||
| - | helper.setSubject(subject) | ||
| - | helper.setText(content, | ||
| - | | ||
| - | mailSender.send(message) | ||
| - | | ||
| - | logger.info(" | ||
| - | logger.debug(" | ||
| - | | ||
| - | } catch (e: Exception) { | ||
| - | logger.error(" | ||
| - | throw RuntimeException(" | ||
| - | } | ||
| - | } | ||
| - | </ | ||
| - | |||
| - | ==== 7.4 Test ==== | ||
| - | |||
| - | <sxh bash> | ||
| - | # 1. Démarrer MailHog | ||
| - | docker-compose up -d mailhog | ||
| - | |||
| - | # 2. Lancer l' | ||
| - | mvn spring-boot: | ||
| - | |||
| - | # 3. Créer une commande | ||
| - | curl -X POST http:// | ||
| - | -H " | ||
| - | -d '{ | ||
| - | " | ||
| - | " | ||
| - | " | ||
| - | }' | ||
| - | |||
| - | # 4. Ouvrir MailHog | ||
| - | open http:// | ||
| - | </ | ||
| - | |||
| - | <WRAP round bloc todo> | ||
| - | **Résultat attendu :** | ||
| - | * Email visible dans MailHog en < 2 secondes | ||
| - | * Sujet : "Order Confirmation #XXX" | ||
| - | * Contenu : Détails de la commande en HTML | ||
| - | </ | ||
| - | |||
| - | <WRAP round bloc important> | ||
| - | **Production vs Développement :** | ||
| - | |||
| - | En **développement** (MailHog) : | ||
| - | <code properties> | ||
| - | spring.mail.host=localhost | ||
| - | spring.mail.port=1025 | ||
| - | </ | ||
| - | |||
| - | En **production** (SMTP réel) : | ||
| - | <code properties> | ||
| - | spring.mail.host=smtp.gmail.com | ||
| - | spring.mail.port=587 | ||
| - | spring.mail.username=${SMTP_USERNAME} | ||
| - | spring.mail.password=${SMTP_PASSWORD} | ||
| - | spring.mail.properties.mail.smtp.auth=true | ||
| - | spring.mail.properties.mail.smtp.starttls.enable=true | ||
| - | </ | ||
| - | |||
| - | ⚠️ **Ne jamais commiter les credentials SMTP !** | ||
| - | </ | ||
| ===== Livrables attendus ===== | ===== Livrables attendus ===== | ||
| Ligne 1668: | 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 1681: | 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** : '' | ||