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. import java.util.Vector;
  19. import org.apache.tools.ant.BuildException;
  20. import org.apache.tools.ant.Task;
  21. import org.apache.tools.ant.util.DateUtils;
  22. /**
  23. * Base class for the various emailing implementations.
  24. *
  25. * @since Ant 1.5
  26. */
  27. public abstract class Mailer {
  28. protected String host = null;
  29. protected int port = -1;
  30. protected String user = null;
  31. protected String password = null;
  32. protected boolean SSL = false;
  33. protected Message message;
  34. protected EmailAddress from;
  35. protected Vector replyToList = null;
  36. protected Vector toList = null;
  37. protected Vector ccList = null;
  38. protected Vector bccList = null;
  39. protected Vector files = null;
  40. protected String subject = null;
  41. protected Task task;
  42. protected boolean includeFileNames = false;
  43. /**
  44. * Sets the mail server
  45. *
  46. * @param host the mail server name
  47. */
  48. public void setHost(String host) {
  49. this.host = host;
  50. }
  51. /**
  52. * Sets the smtp port
  53. *
  54. * @param port the SMTP port
  55. */
  56. public void setPort(int port) {
  57. this.port = port;
  58. }
  59. /**
  60. * Sets the user for smtp auth
  61. *
  62. * @param user the username
  63. * @since ant 1.6
  64. */
  65. public void setUser(String user) {
  66. this.user = user;
  67. }
  68. /**
  69. * Sets the password for smtp auth
  70. *
  71. * @param password the authentication password
  72. * @since ant 1.6
  73. */
  74. public void setPassword(String password) {
  75. this.password = password;
  76. }
  77. /**
  78. * Sets whether the user wants to send the mail through SSL
  79. *
  80. * @param SSL if true use SSL transport
  81. * @since ant 1.6
  82. */
  83. public void setSSL(boolean SSL) {
  84. this.SSL = SSL;
  85. }
  86. /**
  87. * Sets the message
  88. *
  89. * @param m the message content
  90. */
  91. public void setMessage(Message m) {
  92. this.message = m;
  93. }
  94. /**
  95. * Sets the address to send from
  96. *
  97. * @param from the sender
  98. */
  99. public void setFrom(EmailAddress from) {
  100. this.from = from;
  101. }
  102. /**
  103. * Sets the replyto addresses
  104. *
  105. * @param list a vector of reployTo addresses
  106. * @since ant 1.6
  107. */
  108. public void setReplyToList(Vector list) {
  109. this.replyToList = list;
  110. }
  111. /**
  112. * Set the to addresses
  113. *
  114. * @param list a vector of recipient addresses
  115. */
  116. public void setToList(Vector list) {
  117. this.toList = list;
  118. }
  119. /**
  120. * Sets the cc addresses
  121. *
  122. * @param list a vector of cc addresses
  123. */
  124. public void setCcList(Vector list) {
  125. this.ccList = list;
  126. }
  127. /**
  128. * Sets the bcc addresses
  129. *
  130. * @param list a vector of the bcc addresses
  131. */
  132. public void setBccList(Vector list) {
  133. this.bccList = list;
  134. }
  135. /**
  136. * Sets the files to attach
  137. *
  138. * @param files list of files to attach to the email.
  139. */
  140. public void setFiles(Vector files) {
  141. this.files = files;
  142. }
  143. /**
  144. * Sets the subject
  145. *
  146. * @param subject the subject line
  147. */
  148. public void setSubject(String subject) {
  149. this.subject = subject;
  150. }
  151. /**
  152. * Sets the owning task
  153. *
  154. * @param task the owning task instance
  155. */
  156. public void setTask(Task task) {
  157. this.task = task;
  158. }
  159. /**
  160. * Indicates whether filenames should be listed in the body
  161. *
  162. * @param b if true list attached file names in the body content.
  163. */
  164. public void setIncludeFileNames(boolean b) {
  165. this.includeFileNames = b;
  166. }
  167. /**
  168. * This method should send the email
  169. *
  170. * @throws BuildException if the email can't be sent.
  171. */
  172. public abstract void send()
  173. throws BuildException;
  174. /**
  175. * Returns the current Date in a format suitable for a SMTP date
  176. * header.
  177. *
  178. * @return the current date in SMTP suitable format.
  179. *
  180. * @since Ant 1.5
  181. */
  182. protected final String getDate() {
  183. return DateUtils.getDateForHeader();
  184. }
  185. }