KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > lutris > airsent > business > email > EmailManagerImpl


1 /*
2  * Copyright (c) 1999-2001 Lutris Technologies, Inc. All Rights
3  * Reserved.
4  *
5  * This source code file is distributed by Lutris Technologies, Inc. for
6  * use only by licensed users of product(s) that include this source
7  * file. Use of this source file or the software that uses it is covered
8  * by the terms and conditions of the Lutris Enhydra Development License
9  * Agreement included with this product.
10  *
11  * This Software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF
12  * ANY KIND, either express or implied. See the License for the specific terms
13  * governing rights and limitations under the License.
14  *
15  * Contributor(s):
16  *
17  * $Id: EmailManagerImpl.java,v 1.1 2004/08/16 09:33:11 slobodan Exp $
18  */

19
20 package com.lutris.airsent.business.email;
21
22 import com.lutris.util.Config;
23 import com.lutris.util.KeywordValueTable;
24 import com.lutris.airsent.business.AirSentBusinessException;
25 import com.lutris.airsent.spec.email.EmailManager;
26
27 /**
28  * Class declaration
29  *
30  *
31  * @author joseph shoop
32  * @version %I%, %G%
33  */

34 public class EmailManagerImpl implements EmailManager {
35     protected final static String JavaDoc EMAIL_ACTIVE = "Active";
36     protected final static String JavaDoc EMAIL_KEY = "Email";
37     protected final static String JavaDoc MAIL_SERVER_NAME = "MailServer";
38     protected final static String JavaDoc FROM_EMAIL_NAME = "AdminEmailName";
39     protected final static String JavaDoc FROM_EMAIL_ADDRESS = "AdminEmailAddress";
40     protected String JavaDoc mailServer = null;
41     protected String JavaDoc fromName = null;
42     protected String JavaDoc fromAddress = null;
43     protected boolean active = false;
44
45     /**
46      * Plain Constructor
47      *
48      *
49      */

50     public EmailManagerImpl() {}
51
52     /**
53      * Constructor using the Config object to set config variables.
54      *
55      *
56      * @param config
57      *
58      *
59      */

60     public EmailManagerImpl(Config config) throws AirSentBusinessException {
61     try {
62
63         // Get the email config.
64
KeywordValueTable section = config.getSection(EMAIL_KEY);
65
66         mailServer = section.getString(MAIL_SERVER_NAME);
67         fromName = section.getString(FROM_EMAIL_NAME);
68         fromAddress = section.getString(FROM_EMAIL_ADDRESS);
69         active = Boolean.valueOf(section.getString(EMAIL_ACTIVE)).booleanValue();
70     } catch (Exception JavaDoc ex) {
71         throw new AirSentBusinessException("Error sending mail:", ex);
72     }
73     }
74
75     
76     /**
77      * Sends email via smtp.
78      *
79      *
80      * @param to
81      * @param toAddress
82      * @param subject
83      * @param body
84      * @param type
85      *
86      * @throws AirSentBusinessException
87      *
88      *
89      */

90     public void send(String JavaDoc to, String JavaDoc toAddress, String JavaDoc subject,
91              String JavaDoc body,
92              String JavaDoc type) throws AirSentBusinessException {
93     try {
94         if(active) {
95         Email mail = new Email(mailServer);
96         mail.sendMail(fromName, fromAddress, toAddress, subject, type,
97                   body);
98         } else {
99         System.out.println("Email is not active. Edit airSent.conf to activate.");
100         }
101     } catch (Exception JavaDoc ex) {
102         throw new AirSentBusinessException("Error sending mail:", ex);
103     }
104     }
105
106 }
107
108
Popular Tags