1 14 package org.jmanage.core.util; 15 16 import javax.mail.MessagingException ; 17 import javax.mail.Session ; 18 import javax.mail.Message ; 19 import javax.mail.Transport ; 20 import javax.mail.internet.MimeMessage ; 21 import java.util.Properties ; 22 import java.util.logging.Logger ; 23 24 28 public class EmailUtils { 29 30 private static final Logger logger = Loggers.getLogger(EmailUtils.class); 31 32 public static void sendEmail(String to, String subject, String content) 33 throws MessagingException { 34 35 logger.fine("Sending email to: " + to); 36 37 Properties properties = new Properties (); 38 properties.put("mail.user", JManageProperties.getAlertEmailFromName()); 39 properties.put("mail.host", JManageProperties.getEmailHost()); 40 properties.put("mail.from", JManageProperties.getAlertEmailFrom()); 41 properties.put("mail.transport.protocol", "smtp"); 42 Session session = Session.getInstance(properties); 43 MimeMessage message = new MimeMessage (session); 44 message.addRecipients(Message.RecipientType.TO, to); 45 message.setSubject(subject); 46 message.setText(content); 47 Transport.send(message); 48 } 49 } 50 | Popular Tags |