package util;
import [Link].*;
import [Link];
import [Link];
import [Link];
public class EmailService {
private final String email;
private final String motDePasse;
private final Properties props;
public EmailService(String email, String motDePasse) {
[Link] = email;
[Link] = motDePasse;
props = new Properties();
[Link]("[Link]", "true");
[Link]("[Link]", "true");
[Link]("[Link]", "[Link]");
[Link]("[Link]", "587");
public void envoyerNotificationRetard(String emailDestinataire, String nomMembre, String titreLivre,
int joursRetard) throws MessagingException {
String sujet = "Rappel : Livre en retard - " + titreLivre;
String contenu = "Bonjour " + nomMembre + ",\n\n" +
"Nous vous rappelons que le livre '" + titreLivre + "' est en retard de " + joursRetard + " jours.\n"
+
"Veuillez le retourner dès que possible pour éviter des pénalités.\n\n" +
"Cordialement,\nLa Bibliothèque";
envoyerEmail(emailDestinataire, sujet, contenu);
private void envoyerEmail(String destinataire, String sujet, String texte) throws MessagingException {
Session session = [Link](props, new Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(email, motDePasse);
});
Message message = new MimeMessage(session);
[Link](new InternetAddress(email));
[Link]([Link], [Link](destinataire));
[Link](sujet);
[Link](texte);
[Link](message);