Return-Path: Delivered-To: apmail-jakarta-ant-dev-archive@apache.org Received: (qmail 11719 invoked from network); 15 Nov 2001 22:25:58 -0000 Received: from unknown (HELO nagoya.betaversion.org) (192.18.49.131) by daedalus.apache.org with SMTP; 15 Nov 2001 22:25:58 -0000 Received: (qmail 6172 invoked by uid 97); 15 Nov 2001 22:25:13 -0000 Delivered-To: qmlist-jakarta-archive-ant-dev@jakarta.apache.org Received: (qmail 6153 invoked by uid 97); 15 Nov 2001 22:25:13 -0000 Mailing-List: contact ant-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Ant Developers List" Reply-To: "Ant Developers List" Delivered-To: mailing list ant-dev@jakarta.apache.org Received: (qmail 6140 invoked by uid 97); 15 Nov 2001 22:25:12 -0000 Date: 15 Nov 2001 22:11:28 -0000 Message-ID: <20011115221128.15045.qmail@icarus.apache.org> From: sbailliez@apache.org To: jakarta-ant-cvs@apache.org Subject: cvs commit: jakarta-ant/src/main/org/apache/tools/ant/taskdefs SendEmail.java X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N 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 Heavily based on the patch from Magesh Umasankar 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 @@ No, default to "localhost" + mailport + Port of the mail server. + No, default to SMTP default (25) + + subject Email subject line. No 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 = "bcc@you.com"; *   * 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: For additional commands, e-mail: