1 package org.apache.turbine.util.mail;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 import javax.mail.MessagingException;
20
21 import org.apache.torque.util.Criteria;
22
23 /***
24 * This class is used to send simple internet email messages without
25 * attachments.
26 *
27 * @author <a href="mailto:jon@latchkey.com">Jon S. Stevens</a>
28 * @author <a href="mailto:frank.kim@clearink.com">Frank Y. Kim</a>
29 * @author <a href="mailto:bmclaugh@algx.net">Brett McLaughlin</a>
30 * @author <a href="mailto:unknown">Regis Koenig</a>
31 * @version $Id: SimpleEmail.java 264148 2005-08-29 14:21:04Z henning $
32 * @deprecated Use org.apache.commons.mail.SimpleEmail instead.
33 */
34 public class SimpleEmail
35 extends Email
36 {
37 /*** the conentet type for body of the message */
38 private String contentType = null;
39
40 /***
41 * Default constructor.
42 *
43 * @exception MessagingException.
44 */
45 public SimpleEmail() throws MessagingException
46 {
47 super.init();
48 }
49
50 /***
51 * Constructor used to initialize attributes. To create a simple
52 * email you need to pass a Criteria object into the SimpleEmail
53 * constructor which contains:
54 *
55 * <ul>
56 * <li>SENDER_EMAIL</li>
57 * <li>SENDER_NAME</li>
58 * <li>RECEIVER_EMAIL</li>
59 * <li>RECEIVER_NAME</li>
60 * <li>EMAIL_SUBJECT</li>
61 * <li>EMAIL_BODY</li>
62 * </ul>
63 *
64 * Deprecated, since Criteria is deprecated in mail API.
65 *
66 * @param criteria A Criteria.
67 * @exception MessagingException.
68 */
69 public SimpleEmail(Criteria criteria)
70 throws MessagingException
71 {
72 super.init();
73 this.initCriteria(criteria);
74 }
75
76 /***
77 * Uses the criteria to set the fields.
78 *
79 * Deprecated, since the Criteria is deprecated.
80 *
81 * @param criteria A Criteria.
82 * @exception MessagingException.
83 */
84 protected void initCriteria(Criteria criteria)
85 throws MessagingException
86 {
87 super.initCriteria(criteria);
88
89 if (criteria.containsKey(CONTENT_TYPE))
90 {
91 contentType = criteria.getString(CONTENT_TYPE);
92 }
93
94 if (criteria.containsKey(EMAIL_BODY))
95 {
96 setMsg(criteria.getString(EMAIL_BODY));
97 }
98 else
99 {
100 setMsg("NO MESSAGE");
101 }
102 }
103
104 /***
105 * Set the content of the mail
106 *
107 * @param msg A String.
108 * @return An Email.
109 * @exception MessagingException.
110 */
111 public Email setMsg(String msg) throws MessagingException
112 {
113 if (contentType == null)
114 {
115 contentType = TEXT_PLAIN;
116 }
117 message.setContent(msg, contentType);
118 return this;
119 }
120 }