Java tutorial
/* * Copyright (C) 2016 University of Pittsburgh. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * MA 02110-1301 USA */ package edu.pitt.dbmi.ccd.mail; import javax.mail.MessagingException; import org.springframework.mail.javamail.JavaMailSender; import org.springframework.mail.javamail.MimeMessageHelper; /** * * Sep 15, 2015 8:45:14 AM * * @author Kevin V. Bui (kvb2@pitt.edu) */ public class AbstractBasicMail { protected final JavaMailSender javaMailSender; public AbstractBasicMail(JavaMailSender javaMailSender) { this.javaMailSender = javaMailSender; } public void send(String to, String subject, String body, boolean html) throws MessagingException { javaMailSender.send(mimeMessage -> { MimeMessageHelper message = new MimeMessageHelper(mimeMessage); message.setTo(to); message.setSubject(subject); message.setText(body, html); message.setValidateAddresses(true); }); } public void send(String[] to, String subject, String body, boolean html) throws MessagingException { javaMailSender.send(mimeMessage -> { MimeMessageHelper message = new MimeMessageHelper(mimeMessage); message.setTo(to); message.setSubject(subject); message.setText(body, html); message.setValidateAddresses(true); }); } }