sbailliez 01/11/15 14:11:28
Modified: docs/manual/CoreTasks mail.html
src/main/org/apache/tools/mail MailMessage.java
src/main/org/apache/tools/ant/taskdefs SendEmail.java
Log:
Allow port specification for the mail task.
RFE requested by Andrew McConnell <[EMAIL PROTECTED]>
Heavily based on the patch from Magesh Umasankar <[EMAIL PROTECTED]>
Errh, I just realized the full patch was in the first attachment, I though
Magesh forgot to update the mail task. Doh ! :-(
Revision Changes Path
1.5 +5 -0 jakarta-ant/docs/manual/CoreTasks/mail.html
Index: mail.html
===================================================================
RCS file: /home/cvs/jakarta-ant/docs/manual/CoreTasks/mail.html,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- mail.html 2001/10/30 10:05:34 1.4
+++ mail.html 2001/11/15 22:11:27 1.5
@@ -46,6 +46,11 @@
<td align="center" valign="top">No, default to "localhost"</td>
</tr>
<tr>
+ <td valign="top">mailport</td>
+ <td valign="top">Port of the mail server.</td>
+ <td align="center" valign="top">No, default to SMTP default (25)</td>
+ </tr>
+ <tr>
<td valign="top">subject</td>
<td valign="top">Email subject line.</td>
<td align="center" valign="top">No</td>
1.5 +37 -8
jakarta-ant/src/main/org/apache/tools/mail/MailMessage.java
Index: MailMessage.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/src/main/org/apache/tools/mail/MailMessage.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- MailMessage.java 2001/10/28 21:31:00 1.4
+++ MailMessage.java 2001/11/15 22:11:28 1.5
@@ -86,6 +86,7 @@
* String bcc = "[EMAIL PROTECTED]";
*
* MailMessage msg = new MailMessage(mailhost);
+ * msg.setPort(25);
* msg.from(from);
* msg.to(to);
* msg.cc(cc1);
@@ -126,14 +127,33 @@
*/
public class MailMessage {
- String host;
- String from;
- Vector to, cc;
- Hashtable headers;
- MailPrintStream out;
- SmtpResponseReader in;
- Socket socket;
+ /** default port for SMTP: 25 */
+ public final static int DEFAULT_PORT = 25;
+ /** host name for the mail server */
+ private String host;
+
+ /** host port for the mail server */
+ private int port = DEFAULT_PORT;
+
+ /** sender email address */
+ private String from;
+
+ /** list of email addresses to send to */
+ private Vector to;
+
+ /** list of email addresses to cc to */
+ private Vector cc;
+
+ /** headers to send in the mail */
+ private Hashtable headers;
+
+ private MailPrintStream out;
+
+ private SmtpResponseReader in;
+
+ private Socket socket;
+
/**
* Constructs a new MailMessage to send an email.
* Use localhost as the mail server.
@@ -161,6 +181,15 @@
sendHelo();
}
+ /**
+ * Set the port to connect to the SMTP host.
+ * @param port the port to use for connection.
+ * @see #DEFAULT_PORT
+ */
+ public void setPort(int port){
+ this.port = port;
+ }
+
/**
* Sets the from address. Also sets the "From" header. This method should
* be called only once.
@@ -326,7 +355,7 @@
// * * * * * Raw protocol methods below here * * * * *
void connect() throws IOException {
- socket = new Socket(host, 25);
+ socket = new Socket(host, port);
out = new MailPrintStream(
new BufferedOutputStream(
socket.getOutputStream()));
1.5 +14 -5
jakarta-ant/src/main/org/apache/tools/ant/taskdefs/SendEmail.java
Index: SendEmail.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/SendEmail.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- SendEmail.java 2001/10/28 21:26:29 1.4
+++ SendEmail.java 2001/11/15 22:11:28 1.5
@@ -114,6 +114,7 @@
public class SendEmail extends Task {
private String from;
private String mailhost = "localhost";
+ private int mailport = MailMessage.DEFAULT_PORT;
private String message;
private String toList;
private String subject;
@@ -149,7 +150,15 @@
public void setMailhost(String mailhost) {
this.mailhost = mailhost;
}
-
+
+ /**
+ * Sets the mailport parameter of this build task.
+ * @param value mail port name.
+ */
+ public void setMailport(Integer value){
+ this.mailport = value.intValue();
+ }
+
/**
* Sets the message parameter of this build task.
*
@@ -184,12 +193,12 @@
/**
* Executes this build task.
*
- * throws org.apache.tools.ant.BuildException if there is an error
during task
- * execution.
+ * @throws BuildException if there is an error during task execution.
*/
- public void execute() {
+ public void execute() throws BuildException {
try {
MailMessage mailMessage = new MailMessage(mailhost);
+ mailMessage.setPort(mailport);
if (from != null) {
mailMessage.from(from);
@@ -251,7 +260,7 @@
log("Sending email");
mailMessage.sendAndClose();
} catch (IOException ioe) {
- throw new BuildException("IO error sending mail: " +
ioe.getMessage());
+ throw new BuildException("IO error sending mail", ioe);
}
}
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>