1 29 30 package hero.util; 31 32 import java.io.Serializable ; 33 34 import javax.mail.Address ; 35 import javax.mail.Session ; 36 import javax.mail.Transport ; 37 import javax.mail.internet.InternetAddress ; 38 import javax.mail.internet.MimeMessage ; 39 40 public final class MailNotification implements Serializable , java.lang.Cloneable { 41 42 private Session session; 43 44 public void initMailService() 45 { 46 try { 47 BonitaServiceLocator serviceLocator = BonitaServiceLocator.getInstance(); 48 session = (Session ) serviceLocator.getMailSession(BonitaServiceLocator.Services.MAIL_SERVICE); 49 } catch (BonitaServiceException e) { 50 e.printStackTrace(); 51 } 52 } 53 54 public void sendMail(String toAccount, String title,String body) throws Exception { 55 try { 56 this.initMailService(); 57 58 MimeMessage m = new MimeMessage (session); 59 m.setFrom(); 60 Address [] to = new InternetAddress [] {new InternetAddress (toAccount) }; 61 m.setRecipients(javax.mail.Message.RecipientType.TO, to); 62 m.setSubject(title); 63 m.setSentDate(new java.util.Date ()); 64 m.setContent(body,"text/plain"); 65 Transport.send(m); 66 } catch (javax.mail.MessagingException e) { 67 System.out.println("mail-service.xml configuration error: "+e); 68 } 69 } 70 71 public MailNotification(){} 72 73 public Object clone() throws java.lang.CloneNotSupportedException { 74 return super.clone(); 75 } 76 77 } 78 | Popular Tags |