001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: *
017: */
018: package org.apache.tools.ant.taskdefs.email;
019:
020: import java.util.Vector;
021: import org.apache.tools.ant.BuildException;
022: import org.apache.tools.ant.Task;
023: import org.apache.tools.ant.util.DateUtils;
024:
025: /**
026: * Base class for the various emailing implementations.
027: *
028: * @since Ant 1.5
029: */
030: public abstract class Mailer {
031: // CheckStyle:VisibilityModifier OFF - bc
032: protected String host = null;
033: protected int port = -1;
034: protected String user = null;
035: protected String password = null;
036: // CheckStyle:MemberNameCheck OFF - bc
037: protected boolean SSL = false;
038: // CheckStyle:MemberNameCheck ON
039: protected Message message;
040: protected EmailAddress from;
041: protected Vector replyToList = null;
042: protected Vector toList = null;
043: protected Vector ccList = null;
044: protected Vector bccList = null;
045: protected Vector files = null;
046: protected String subject = null;
047: protected Task task;
048: protected boolean includeFileNames = false;
049: protected Vector headers = null;
050:
051: // CheckStyle:VisibilityModifier ON
052:
053: /**
054: * Set the mail server.
055: *
056: * @param host the mail server name.
057: */
058: public void setHost(String host) {
059: this .host = host;
060: }
061:
062: /**
063: * Set the smtp port.
064: *
065: * @param port the SMTP port.
066: */
067: public void setPort(int port) {
068: this .port = port;
069: }
070:
071: /**
072: * Set the user for smtp auth.
073: *
074: * @param user the username.
075: * @since Ant 1.6
076: */
077: public void setUser(String user) {
078: this .user = user;
079: }
080:
081: /**
082: * Set the password for smtp auth.
083: *
084: * @param password the authentication password.
085: * @since Ant 1.6
086: */
087: public void setPassword(String password) {
088: this .password = password;
089: }
090:
091: /**
092: * Set whether to send the mail through SSL.
093: *
094: * @param ssl if true use SSL transport.
095: * @since Ant 1.6
096: */
097: public void setSSL(boolean ssl) {
098: this .SSL = ssl;
099: }
100:
101: /**
102: * Set the message.
103: *
104: * @param m the message content.
105: */
106: public void setMessage(Message m) {
107: this .message = m;
108: }
109:
110: /**
111: * Set the address to send from.
112: *
113: * @param from the sender.
114: */
115: public void setFrom(EmailAddress from) {
116: this .from = from;
117: }
118:
119: /**
120: * Set the replyto addresses.
121: *
122: * @param list a vector of reployTo addresses.
123: * @since Ant 1.6
124: */
125: public void setReplyToList(Vector list) {
126: this .replyToList = list;
127: }
128:
129: /**
130: * Set the to addresses.
131: *
132: * @param list a vector of recipient addresses.
133: */
134: public void setToList(Vector list) {
135: this .toList = list;
136: }
137:
138: /**
139: * Set the cc addresses.
140: *
141: * @param list a vector of cc addresses.
142: */
143: public void setCcList(Vector list) {
144: this .ccList = list;
145: }
146:
147: /**
148: * Set the bcc addresses.
149: *
150: * @param list a vector of the bcc addresses.
151: */
152: public void setBccList(Vector list) {
153: this .bccList = list;
154: }
155:
156: /**
157: * Set 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: * Set the subject.
167: *
168: * @param subject the subject line.
169: */
170: public void setSubject(String subject) {
171: this .subject = subject;
172: }
173:
174: /**
175: * Set the owning task.
176: *
177: * @param task the owning task instance.
178: */
179: public void setTask(Task task) {
180: this .task = task;
181: }
182:
183: /**
184: * Indicate whether filenames should be listed in the body.
185: *
186: * @param b if true list attached file names in the body content.
187: */
188: public void setIncludeFileNames(boolean b) {
189: this .includeFileNames = b;
190: }
191:
192: /**
193: * Set the generic headers to add to the email.
194: * @param v a Vector presumed to contain Header objects.
195: * @since Ant 1.7
196: */
197: public void setHeaders(Vector v) {
198: this .headers = v;
199: }
200:
201: /**
202: * Send the email.
203: *
204: * @throws BuildException if the email can't be sent.
205: */
206: public abstract void send() 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 getDate() {
217: return DateUtils.getDateForHeader();
218: }
219: }
|