KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > hero > util > MailNotification


1 /**
2  *
3  * Bonita
4  * Copyright (C) 1999 Bull S.A.
5  * Bull 68 route de versailles 78434 Louveciennes Cedex France
6  * Further information: bonita@objectweb.org
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
21  * USA
22  *
23  *
24 --------------------------------------------------------------------------
25  * $Id: MailNotification.java,v 1.1 2004/07/30 14:57:56 mvaldes Exp $
26  *
27 --------------------------------------------------------------------------
28  */

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