Java tutorial
package nc.noumea.mairie.appock.core.utility; /*- * #%L * Logiciel de Gestion des approvisionnements et des stocks des fournitures administratives de la Mairie de Nouma * %% * Copyright (C) 2017 Mairie de Nouma, Nouvelle-Caldonie * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public * License along with this program. If not, see * <http://www.gnu.org/licenses/gpl-3.0.html>. * #L% */ import java.io.UnsupportedEncodingException; import java.util.ArrayList; import java.util.List; import javax.mail.internet.InternetAddress; import org.apache.commons.lang.StringUtils; import nc.noumea.mairie.appock.core.security.AppUser; import nc.noumea.mairie.appock.entity.BonLivraison; /** * Modlise un mail gr par l'application (les cls/contenus sont stocks en paramtres applicatifs) * @author AgileSoft.NC */ public class AppockMail { List<InternetAddress> listeDestinataire = new ArrayList<>(); InternetAddress from; String sujet; String contenu; BonLivraison bonLivraison; public void addDestinataire(List<AppUser> listeAppUser) throws UnsupportedEncodingException { for (AppUser appUser : listeAppUser) { addDestinataire(appUser); } } public void addDestinataire(AppUser user) throws UnsupportedEncodingException { if (user == null) { return; } if (StringUtils.isBlank(user.getEmail())) { return; } this.listeDestinataire.add(createInternetAddress(user)); } private InternetAddress createInternetAddress(AppUser user) throws UnsupportedEncodingException { if (user == null) { throw new IllegalArgumentException(); } return new InternetAddress(user.getEmail(), user.getNomComplet()); } public void setFrom(AppUser user) throws UnsupportedEncodingException { this.from = user == null ? null : createInternetAddress(user); } public String getContenu() { return contenu; } public void setContenu(String contenu) { this.contenu = contenu; } public List<InternetAddress> getListeDestinataire() { return listeDestinataire; } public InternetAddress getFrom() { return from; } public String getSujet() { return sujet; } public void setSujet(String sujet) { this.sujet = sujet; } public BonLivraison getBonLivraison() { return bonLivraison; } public void setBonLivraison(BonLivraison bonLivraison) { this.bonLivraison = bonLivraison; } }