1 | /*
|
---|
2 | * Copyright 2002-2004 The Apache Software Foundation
|
---|
3 | *
|
---|
4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
---|
5 | * you may not use this file except in compliance with the License.
|
---|
6 | * You may obtain a copy of the License at
|
---|
7 | *
|
---|
8 | * http://www.apache.org/licenses/LICENSE-2.0
|
---|
9 | *
|
---|
10 | * Unless required by applicable law or agreed to in writing, software
|
---|
11 | * distributed under the License is distributed on an "AS IS" BASIS,
|
---|
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
---|
13 | * See the License for the specific language governing permissions and
|
---|
14 | * limitations under the License.
|
---|
15 | *
|
---|
16 | */
|
---|
17 | package org.apache.tools.ant.taskdefs.email;
|
---|
18 |
|
---|
19 | import java.util.Vector;
|
---|
20 | import org.apache.tools.ant.BuildException;
|
---|
21 | import org.apache.tools.ant.Task;
|
---|
22 | import org.apache.tools.ant.util.DateUtils;
|
---|
23 |
|
---|
24 | /**
|
---|
25 | * Base class for the various emailing implementations.
|
---|
26 | *
|
---|
27 | * @since Ant 1.5
|
---|
28 | */
|
---|
29 | public abstract class Mailer {
|
---|
30 | protected String host = null;
|
---|
31 | protected int port = -1;
|
---|
32 | protected String user = null;
|
---|
33 | protected String password = null;
|
---|
34 | protected boolean SSL = false;
|
---|
35 | protected Message message;
|
---|
36 | protected EmailAddress from;
|
---|
37 | protected Vector replyToList = null;
|
---|
38 | protected Vector toList = null;
|
---|
39 | protected Vector ccList = null;
|
---|
40 | protected Vector bccList = null;
|
---|
41 | protected Vector files = null;
|
---|
42 | protected String subject = null;
|
---|
43 | protected Task task;
|
---|
44 | protected boolean includeFileNames = false;
|
---|
45 |
|
---|
46 | /**
|
---|
47 | * Sets the mail server
|
---|
48 | *
|
---|
49 | * @param host the mail server name
|
---|
50 | */
|
---|
51 | public void setHost(String host) {
|
---|
52 | this.host = host;
|
---|
53 | }
|
---|
54 |
|
---|
55 |
|
---|
56 | /**
|
---|
57 | * Sets the smtp port
|
---|
58 | *
|
---|
59 | * @param port the SMTP port
|
---|
60 | */
|
---|
61 | public void setPort(int port) {
|
---|
62 | this.port = port;
|
---|
63 | }
|
---|
64 |
|
---|
65 | /**
|
---|
66 | * Sets the user for smtp auth
|
---|
67 | *
|
---|
68 | * @param user the username
|
---|
69 | * @since ant 1.6
|
---|
70 | */
|
---|
71 | public void setUser(String user) {
|
---|
72 | this.user = user;
|
---|
73 | }
|
---|
74 |
|
---|
75 | /**
|
---|
76 | * Sets the password for smtp auth
|
---|
77 | *
|
---|
78 | * @param password the authentication password
|
---|
79 | * @since ant 1.6
|
---|
80 | */
|
---|
81 | public void setPassword(String password) {
|
---|
82 | this.password = password;
|
---|
83 | }
|
---|
84 |
|
---|
85 | /**
|
---|
86 | * Sets whether the user wants to send the mail through SSL
|
---|
87 | *
|
---|
88 | * @param SSL if true use SSL transport
|
---|
89 | * @since ant 1.6
|
---|
90 | */
|
---|
91 | public void setSSL(boolean SSL) {
|
---|
92 | this.SSL = SSL;
|
---|
93 | }
|
---|
94 |
|
---|
95 | /**
|
---|
96 | * Sets the message
|
---|
97 | *
|
---|
98 | * @param m the message content
|
---|
99 | */
|
---|
100 | public void setMessage(Message m) {
|
---|
101 | this.message = m;
|
---|
102 | }
|
---|
103 |
|
---|
104 |
|
---|
105 | /**
|
---|
106 | * Sets the address to send from
|
---|
107 | *
|
---|
108 | * @param from the sender
|
---|
109 | */
|
---|
110 | public void setFrom(EmailAddress from) {
|
---|
111 | this.from = from;
|
---|
112 | }
|
---|
113 |
|
---|
114 |
|
---|
115 | /**
|
---|
116 | * Sets the replyto addresses
|
---|
117 | *
|
---|
118 | * @param list a vector of reployTo addresses
|
---|
119 | * @since ant 1.6
|
---|
120 | */
|
---|
121 | public void setReplyToList(Vector list) {
|
---|
122 | this.replyToList = list;
|
---|
123 | }
|
---|
124 |
|
---|
125 |
|
---|
126 | /**
|
---|
127 | * Set the to addresses
|
---|
128 | *
|
---|
129 | * @param list a vector of recipient addresses
|
---|
130 | */
|
---|
131 | public void setToList(Vector list) {
|
---|
132 | this.toList = list;
|
---|
133 | }
|
---|
134 |
|
---|
135 |
|
---|
136 | /**
|
---|
137 | * Sets the cc addresses
|
---|
138 | *
|
---|
139 | * @param list a vector of cc addresses
|
---|
140 | */
|
---|
141 | public void setCcList(Vector list) {
|
---|
142 | this.ccList = list;
|
---|
143 | }
|
---|
144 |
|
---|
145 |
|
---|
146 | /**
|
---|
147 | * Sets the bcc addresses
|
---|
148 | *
|
---|
149 | * @param list a vector of the bcc addresses
|
---|
150 | */
|
---|
151 | public void setBccList(Vector list) {
|
---|
152 | this.bccList = list;
|
---|
153 | }
|
---|
154 |
|
---|
155 |
|
---|
156 | /**
|
---|
157 | * Sets the files to attach
|
---|
158 | *
|
---|
159 | * @param files list of files to attach to the email.
|
---|
160 | */
|
---|
161 | public void setFiles(Vector files) {
|
---|
162 | this.files = files;
|
---|
163 | }
|
---|
164 |
|
---|
165 |
|
---|
166 | /**
|
---|
167 | * Sets the subject
|
---|
168 | *
|
---|
169 | * @param subject the subject line
|
---|
170 | */
|
---|
171 | public void setSubject(String subject) {
|
---|
172 | this.subject = subject;
|
---|
173 | }
|
---|
174 |
|
---|
175 |
|
---|
176 | /**
|
---|
177 | * Sets the owning task
|
---|
178 | *
|
---|
179 | * @param task the owning task instance
|
---|
180 | */
|
---|
181 | public void setTask(Task task) {
|
---|
182 | this.task = task;
|
---|
183 | }
|
---|
184 |
|
---|
185 |
|
---|
186 | /**
|
---|
187 | * Indicates whether filenames should be listed in the body
|
---|
188 | *
|
---|
189 | * @param b if true list attached file names in the body content.
|
---|
190 | */
|
---|
191 | public void setIncludeFileNames(boolean b) {
|
---|
192 | this.includeFileNames = b;
|
---|
193 | }
|
---|
194 |
|
---|
195 |
|
---|
196 | /**
|
---|
197 | * This method should send the email
|
---|
198 | *
|
---|
199 | * @throws BuildException if the email can't be sent.
|
---|
200 | */
|
---|
201 | public abstract void send()
|
---|
202 | throws BuildException;
|
---|
203 |
|
---|
204 | /**
|
---|
205 | * Returns the current Date in a format suitable for a SMTP date
|
---|
206 | * header.
|
---|
207 | *
|
---|
208 | * @return the current date in SMTP suitable format.
|
---|
209 | *
|
---|
210 | * @since Ant 1.5
|
---|
211 | */
|
---|
212 | protected final String getDate() {
|
---|
213 | return DateUtils.getDateForHeader();
|
---|
214 | }
|
---|
215 | }
|
---|
216 |
|
---|