KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tools > ant > taskdefs > email > Mailer


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */

18 package org.apache.tools.ant.taskdefs.email;
19
20 import java.util.Vector JavaDoc;
21 import org.apache.tools.ant.BuildException;
22 import org.apache.tools.ant.Task;
23 import org.apache.tools.ant.util.DateUtils;
24
25 /**
26  * Base class for the various emailing implementations.
27  *
28  * @since Ant 1.5
29  */

30 public abstract class Mailer {
31     // CheckStyle:VisibilityModifier OFF - bc
32
protected String JavaDoc host = null;
33     protected int port = -1;
34     protected String JavaDoc user = null;
35     protected String JavaDoc password = null;
36     // CheckStyle:MemberNameCheck OFF - bc
37
protected boolean SSL = false;
38     // CheckStyle:MemberNameCheck ON
39
protected Message message;
40     protected EmailAddress from;
41     protected Vector JavaDoc replyToList = null;
42     protected Vector JavaDoc toList = null;
43     protected Vector JavaDoc ccList = null;
44     protected Vector JavaDoc bccList = null;
45     protected Vector JavaDoc files = null;
46     protected String JavaDoc subject = null;
47     protected Task task;
48     protected boolean includeFileNames = false;
49     protected Vector JavaDoc headers = null;
50     // CheckStyle:VisibilityModifier ON
51

52     /**
53      * Set the mail server.
54      *
55      * @param host the mail server name.
56      */

57     public void setHost(String JavaDoc host) {
58         this.host = host;
59     }
60
61     /**
62      * Set the smtp port.
63      *
64      * @param port the SMTP port.
65      */

66     public void setPort(int port) {
67         this.port = port;
68     }
69
70     /**
71      * Set the user for smtp auth.
72      *
73      * @param user the username.
74      * @since Ant 1.6
75      */

76     public void setUser(String JavaDoc user) {
77         this.user = user;
78     }
79
80     /**
81      * Set the password for smtp auth.
82      *
83      * @param password the authentication password.
84      * @since Ant 1.6
85      */

86     public void setPassword(String JavaDoc password) {
87         this.password = password;
88     }
89
90     /**
91      * Set whether to send the mail through SSL.
92      *
93      * @param ssl if true use SSL transport.
94      * @since Ant 1.6
95      */

96     public void setSSL(boolean ssl) {
97         this.SSL = ssl;
98     }
99
100     /**
101      * Set the message.
102      *
103      * @param m the message content.
104      */

105     public void setMessage(Message m) {
106         this.message = m;
107     }
108
109     /**
110      * Set the address to send from.
111      *
112      * @param from the sender.
113      */

114     public void setFrom(EmailAddress from) {
115         this.from = from;
116     }
117
118     /**
119      * Set the replyto addresses.
120      *
121      * @param list a vector of reployTo addresses.
122      * @since Ant 1.6
123      */

124     public void setReplyToList(Vector JavaDoc list) {
125         this.replyToList = list;
126     }
127
128     /**
129      * Set the to addresses.
130      *
131      * @param list a vector of recipient addresses.
132      */

133     public void setToList(Vector JavaDoc list) {
134         this.toList = list;
135     }
136
137     /**
138      * Set the cc addresses.
139      *
140      * @param list a vector of cc addresses.
141      */

142     public void setCcList(Vector JavaDoc list) {
143         this.ccList = list;
144     }
145
146     /**
147      * Set the bcc addresses.
148      *
149      * @param list a vector of the bcc addresses.
150      */

151     public void setBccList(Vector JavaDoc list) {
152         this.bccList = list;
153     }
154
155     /**
156      * Set the files to attach.
157      *
158      * @param files list of files to attach to the email.
159      */

160     public void setFiles(Vector JavaDoc files) {
161         this.files = files;
162     }
163
164     /**
165      * Set the subject.
166      *
167      * @param subject the subject line.
168      */

169     public void setSubject(String JavaDoc subject) {
170         this.subject = subject;
171     }
172
173     /**
174      * Set the owning task.
175      *
176      * @param task the owning task instance.
177      */

178     public void setTask(Task task) {
179         this.task = task;
180     }
181
182     /**
183      * Indicate whether filenames should be listed in the body.
184      *
185      * @param b if true list attached file names in the body content.
186      */

187     public void setIncludeFileNames(boolean b) {
188         this.includeFileNames = b;
189     }
190
191     /**
192      * Set the generic headers to add to the email.
193      * @param v a Vector presumed to contain Header objects.
194      * @since Ant 1.7
195      */

196     public void setHeaders(Vector JavaDoc v) {
197         this.headers = v;
198     }
199
200     /**
201      * Send the email.
202      *
203      * @throws BuildException if the email can't be sent.
204      */

205     public abstract void send()
206          throws BuildException;
207
208     /**
209      * Return the current Date in a format suitable for a SMTP date
210      * header.
211      *
212      * @return the current date in SMTP suitable format.
213      *
214      * @since Ant 1.5
215      */

216     protected final String JavaDoc getDate() {
217         return DateUtils.getDateForHeader();
218     }
219 }
220
221
Popular Tags