View Javadoc

1   /* $Id: EmailMessengerFactory.java,v 1.4 2004/03/24 18:31:33 jdt Exp $
2    * Created on Mar 14, 2004 by jdt
3    * Copyright (C) AstroGrid. All rights reserved.
4    *
5    * This software is published under the terms of the AstroGrid 
6    * Software License version 1.2, a copy of which has been included 
7    * with this distribution in the LICENSE.txt file. 
8    */
9   package org.astrogrid.portal.cocoon.messaging;
10  import java.util.Properties;
11  
12  import javax.mail.Session;
13  /***
14   * Creates Messengers that dispatch emails
15   * 
16   * @author jdt
17   */
18  public final class EmailMessengerFactory  {
19      /***
20       * The mail session
21       */
22      private Session session;
23  
24      /***
25       * Constructor
26       * @param smtpServer IP address of server, port 25 assumed
27       * @param user username of sender's account
28       * @param password password for said account
29       * @param returnAddress who shall we say it's from?
30       */
31      public EmailMessengerFactory(final String smtpServer, final String user, final String password,final String returnAddress) {
32          final Properties props = new Properties();
33          props.setProperty("mail.transport.protocol", "smtp");
34          props.setProperty("mail.host", smtpServer);
35          props.setProperty("mail.user", user);
36          props.setProperty("mail.password", password);
37          props.setProperty("mail.from", returnAddress);
38          session = Session.getInstance(props,null);
39     }
40  
41      /***
42       * Create a messenger that can be used to message these recipients
43       * @param recipients comma separated list of recipients
44       * @return an EmailMessenger
45       */
46      public Messenger getEmailMessenger(final String recipients) {
47              return new EmailMessenger(session, recipients);
48      }
49      
50      /***
51       * Create a messenger that can be used to message these recipients
52       * @param recipients comma separated list of recipients
53       * @param mock return a mock messenger if true
54       * @return an EmailMessenger
55       */
56      public Messenger getEmailMessenger(final String recipients,final boolean mock) {
57          if (mock) {
58              return new MockEmailMessenger(session, recipients);
59          } else {
60              return getEmailMessenger(recipients);
61          }
62      }
63      
64  
65      
66  }
67  
68  
69  
70  
71  /*
72   *  $Log: EmailMessengerFactory.java,v $
73   *  Revision 1.4  2004/03/24 18:31:33  jdt
74   *  Merge from PLGN_JDT_bz#201
75   *
76   *  Revision 1.3.2.1  2004/03/23 00:47:39  jdt
77   *  added facility to return a mock mailer for testing
78   *
79   *  Revision 1.3  2004/03/19 13:02:25  jdt
80   *  Pruned the log messages - they cause conflicts on merge, 
81   *  best just to reduce them to the merge message.
82   *
83   *  Revision 1.2  2004/03/19 12:40:09  jdt
84   *  Merge from PLGN_JDT_bz199b.
85   *  Refactored log in pages to use xsp and xsl style sheets.  
86   *  Added pages for requesting a login, and requesting
87   *  a password reminder.
88   *
89   */