1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 package org.talika.tarsis.factory;
24
25 import java.util.Properties;
26 import javax.mail.Session;
27
28 /**
29 * SMTP mail <code>Session</code> factory implementation of <code>Factory</code>
30 * interface.<br>
31 * <br>
32 * Creates a <code>Session</code> object from given parameters.<br>
33 * <br>
34 * Parameters given to create <code>Session</code> are:
35 * <ul>
36 * <li>smtpHost - SMTP server.</li>
37 * </ul>
38 *
39 * @author Jose M. Palomar
40 * @version $Revision: 119 $
41 * @see javax.mail.Session
42 */
43 public final class SmtpMailSession extends FactoryService {
44
45
46
47
48 /**
49 * Init properties for <code>Session</code>.
50 */
51 private Properties env = new Properties();
52
53
54 /**
55 * Creates a new <code>SmtpMailSession</code> object.
56 */
57 public SmtpMailSession() {
58 this.env.put("mail.trasport.protocol", "smtp");
59 }
60
61
62 /**
63 * Sets smtpHost parameter.
64 *
65 * @param smtpHost String SMTP server.
66 */
67 public void setSmtpHost(String smtpHost) {
68 this.env.put("mail.smtp.host", smtpHost);
69 }
70
71 /**
72 * Returns name of service.
73 *
74 * @return String name of service.
75 * @see org.talika.tarsis.service.Service#getName()
76 */
77 public String getName() {
78 return "SmtpMailSessionFactory";
79 }
80
81 /**
82 * Returns a new <code>Session</code> instance created by this factory.
83 *
84 * @return Object a new <code>Session</code> instance created by this factory.
85 * @see org.talika.tarsis.factory.Factory#getInstance()
86 */
87 public Object getInstance() {
88 return getMailSession();
89 }
90
91 /**
92 * Returns a new <code>Session</code> instance created by this factory.
93 *
94 * @return Session a new <code>Session</code> instance created by this factory.
95 */
96 public Session getMailSession() {
97 return Session.getDefaultInstance(env);
98 }
99
100 }