diff --git a/docs/manual/CoreTasks/mail.html b/docs/manual/CoreTasks/mail.html index 234472873..afca074e1 100644 --- a/docs/manual/CoreTasks/mail.html +++ b/docs/manual/CoreTasks/mail.html @@ -32,6 +32,11 @@ Library Dependencies for more information. Either a from attribute, or a <from> element. + + replyto + Replyto email address. + No + tolist Comma-separated list of recipients. @@ -116,7 +121,7 @@ Library Dependencies for more information.

Parameters specified as nested elements

-

to / cc / bcc / from

+

to / cc / bcc / from/ replyto

Adds an email address element. It takes the following attributes:

@@ -187,7 +192,8 @@ the <message> element.

 <mail mailhost="smtp.myisp.com" mailport="1025" subject="Test build">
-  <from address="me@myisp.com"/>
+  <from address="config@myisp.com"/>
+  <replyto address="me@myisp.com"/>
   <to address="all@xyz.com"/>
   <message>The ${buildname} nightly build has completed</message>
   <fileset dir="dist">
@@ -196,8 +202,9 @@ the <message> element.

</mail>
-

Sends an eMail from me@myisp.com to all@xyz.com with a subject of -Test Build and attaches any zip files from the dist directory.  The +

Sends an eMail from config@myisp.com to all@xyz.com with a subject of +Test Build. Replies to this email will go to me@myisp.com. +Any zip files from the dist directory are attached.  The task will attempt to use JavaMail and fall back to UU encoding or no encoding in that order depending on what support classes are available. ${buildname} will be replaced with the buildname property's value.

diff --git a/docs/manual/listeners.html b/docs/manual/listeners.html index 6475cf174..ede7ff28a 100644 --- a/docs/manual/listeners.html +++ b/docs/manual/listeners.html @@ -130,6 +130,11 @@ control for turning off success or failure messages individually.

+ + + + + @@ -314,7 +319,7 @@ developers.


-

Copyright © 2000-2002 Apache Software Foundation. All rights +

Copyright © 2000-2003 Apache Software Foundation. All rights Reserved.

diff --git a/src/main/org/apache/tools/ant/listener/MailLogger.java b/src/main/org/apache/tools/ant/listener/MailLogger.java index 23b4f8a5c..2af3eba58 100644 --- a/src/main/org/apache/tools/ant/listener/MailLogger.java +++ b/src/main/org/apache/tools/ant/listener/MailLogger.java @@ -153,12 +153,12 @@ public class MailLogger extends DefaultLogger { String mailhost = getValue(properties, "mailhost", "localhost"); int port = Integer.parseInt(getValue(properties,"port",String.valueOf(MailMessage.DEFAULT_PORT))); String from = getValue(properties, "from", null); - + String replytoList = getValue(properties,"replyto",""); String toList = getValue(properties, prefix + ".to", null); String subject = getValue(properties, prefix + ".subject", (success) ? "Build Success" : "Build Failure"); - sendMail(mailhost, port, from, toList, subject, buffer.substring(0)); + sendMail(mailhost, port, from, replytoList, toList, subject, buffer.substring(0)); } catch (Exception e) { System.out.println("MailLogger failed to send e-mail!"); e.printStackTrace(System.err); @@ -211,18 +211,24 @@ public class MailLogger extends DefaultLogger { * @param mailhost mail server * @param port mail server port number * @param from from address + * @param replyToList comma-separated replyto list * @param toList comma-separated recipient list * @param subject mail subject * @param message mail body * @exception IOException thrown if sending message fails */ - private void sendMail(String mailhost, int port, String from, String toList, + private void sendMail(String mailhost, int port, String from, String replyToList, String toList, String subject, String message) throws IOException { MailMessage mailMessage = new MailMessage(mailhost, port); mailMessage.setHeader("Date", DateUtils.getDateForHeader()); mailMessage.from(from); - + if (!replyToList.equals("")) { + StringTokenizer t = new StringTokenizer(replyToList, ", ", false); + while (t.hasMoreTokens()) { + mailMessage.replyto(t.nextToken()); + } + } StringTokenizer t = new StringTokenizer(toList, ", ", false); while (t.hasMoreTokens()) { mailMessage.to(t.nextToken()); diff --git a/src/main/org/apache/tools/ant/taskdefs/email/EmailTask.java b/src/main/org/apache/tools/ant/taskdefs/email/EmailTask.java index 5c97d5afc..a29bb97d3 100644 --- a/src/main/org/apache/tools/ant/taskdefs/email/EmailTask.java +++ b/src/main/org/apache/tools/ant/taskdefs/email/EmailTask.java @@ -77,6 +77,7 @@ import org.apache.tools.ant.types.FileSet; * @author paulo.gaspar@krankikom.de Paulo Gaspar * @author roxspring@imapmail.org Rob Oxspring * @author Aleksandr Ishutin + * @author Antoine Levy-Lambert * @since Ant 1.5 * @ant.task name="mail" category="network" */ @@ -120,9 +121,11 @@ public class EmailTask private boolean failOnError = true; private boolean includeFileNames = false; private String messageMimeType = null; - + /** special headers */ /** sender */ private EmailAddress from = null; + /** replyto */ + private Vector replyToList = new Vector(); /** TO recipients */ private Vector toList = new Vector(); /** CC (Carbon Copy) recipients */ @@ -135,6 +138,10 @@ public class EmailTask private Vector filesets = new Vector(); /** Character set for MimeMailer*/ private String charset=null; + /** if set to true, the email will not be actually sent */ + private boolean debugonly=false; + /** a location where to print the email message */ + private File debugoutput; /** @@ -265,6 +272,28 @@ public class EmailTask } + /** + * Adds a replyto address element + * + * @param address The address to reply to + * @since ant 1.6 + */ + public void addReplyTo(EmailAddress address) { + this.replyToList.add(address); + } + + + /** + * Shorthand to set the replyto address element + * + * @param address The address to which replies should be directed + * @since ant 1.6 + */ + public void setReplyTo(String address) { + this.replyToList.add(new EmailAddress(address)); + } + + /** * Adds a to address element * @@ -501,6 +530,7 @@ public class EmailTask // let the user know what's going to happen log("Sending email: " + subject, Project.MSG_INFO); log("From " + from, Project.MSG_VERBOSE); + log("ReplyTo " + replyToList,Project.MSG_VERBOSE); log("To " + toList, Project.MSG_VERBOSE); log("Cc " + ccList, Project.MSG_VERBOSE); log("Bcc " + bccList, Project.MSG_VERBOSE); @@ -510,6 +540,7 @@ public class EmailTask mailer.setPort(port); mailer.setMessage(message); mailer.setFrom(from); + mailer.setReplyToList(replyToList); mailer.setToList(toList); mailer.setCcList(ccList); mailer.setBccList(bccList); diff --git a/src/main/org/apache/tools/ant/taskdefs/email/Mailer.java b/src/main/org/apache/tools/ant/taskdefs/email/Mailer.java index 7cd36ecb6..d88be3962 100644 --- a/src/main/org/apache/tools/ant/taskdefs/email/Mailer.java +++ b/src/main/org/apache/tools/ant/taskdefs/email/Mailer.java @@ -69,6 +69,7 @@ abstract class Mailer { protected int port = -1; protected Message message; protected EmailAddress from; + protected Vector replyToList = null; protected Vector toList = null; protected Vector ccList = null; protected Vector bccList = null; @@ -117,6 +118,17 @@ abstract class Mailer { } + /** + * Sets the replyto addresses + * + * @param list + * @since ant 1.6 + */ + public void setReplyToList(Vector list) { + this.replyToList = list; + } + + /** * Set the to addresses * diff --git a/src/main/org/apache/tools/ant/taskdefs/email/MimeMailer.java b/src/main/org/apache/tools/ant/taskdefs/email/MimeMailer.java index 246d38b6c..21caa352d 100644 --- a/src/main/org/apache/tools/ant/taskdefs/email/MimeMailer.java +++ b/src/main/org/apache/tools/ant/taskdefs/email/MimeMailer.java @@ -170,7 +170,8 @@ class MimeMailer extends Mailer { msg.setFrom(new InternetAddress(from.getAddress(), from.getName())); } - + // set the reply to addresses + msg.setReplyTo(internetAddresses(replyToList)); msg.setRecipients(Message.RecipientType.TO, internetAddresses(toList)); msg.setRecipients(Message.RecipientType.CC, diff --git a/src/main/org/apache/tools/ant/taskdefs/email/PlainMailer.java b/src/main/org/apache/tools/ant/taskdefs/email/PlainMailer.java index 00addf82b..4ddf7b0c2 100644 --- a/src/main/org/apache/tools/ant/taskdefs/email/PlainMailer.java +++ b/src/main/org/apache/tools/ant/taskdefs/email/PlainMailer.java @@ -1,7 +1,7 @@ /* * The Apache Software License, Version 1.1 * - * Copyright (c) 2002 The Apache Software Foundation. All rights + * Copyright (c) 2002-2003 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without @@ -82,6 +82,11 @@ class PlainMailer extends Mailer { Enumeration e; + e = replyToList.elements(); + while (e.hasMoreElements()) { + mailMessage.replyto(e.nextElement().toString()); + } + e = toList.elements(); while (e.hasMoreElements()) { mailMessage.to(e.nextElement().toString()); @@ -122,7 +127,6 @@ class PlainMailer extends Mailer { } - /** * Attaches a file to this email * diff --git a/src/main/org/apache/tools/mail/MailMessage.java b/src/main/org/apache/tools/mail/MailMessage.java index 67a236fad..c112c6791 100644 --- a/src/main/org/apache/tools/mail/MailMessage.java +++ b/src/main/org/apache/tools/mail/MailMessage.java @@ -1,7 +1,7 @@ /* * The Apache Software License, Version 1.1 * - * Copyright (c) 2000-2002 The Apache Software Foundation. All rights + * Copyright (c) 2000-2003 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without @@ -143,6 +143,9 @@ public class MailMessage { /** sender email address */ private String from; + /** list of email addresses to reply to */ + private Vector replyto; + /** list of email addresses to send to */ private Vector to; @@ -190,10 +193,11 @@ public class MailMessage { public MailMessage(String host, int port) throws IOException{ this.port = port; this.host = host; + replyto = new Vector(); to = new Vector(); cc = new Vector(); headers = new Hashtable(); - setHeader("X-Mailer", "org.apache.tools.mail.MailMessage (jakarta.apache.org)"); + setHeader("X-Mailer", "org.apache.tools.mail.MailMessage (ant.apache.org)"); connect(); sendHelo(); } @@ -218,6 +222,16 @@ public class MailMessage { this.from = from; } + /** + * Sets the replyto address + * This method may be + * called multiple times. + * + */ + public void replyto(String rto) { + this.replyto.addElement(rto); + } + /** * Sets the to address. Also sets the "To" header. This method may be * called multiple times. @@ -277,6 +291,7 @@ public class MailMessage { */ public PrintStream getPrintStream() throws IOException { setFromHeader(); + setReplyToHeader(); setToHeader(); setCcHeader(); sendData(); @@ -288,6 +303,9 @@ public class MailMessage { setHeader("From", from); } + void setReplyToHeader() { + setHeader("Reply-To", vectorToList(replyto)); + } void setToHeader() { setHeader("To", vectorToList(to)); }
Mail "from" address Yes, if mail needs to be sent
MailLogger.replytoMail "replyto" address(es), comma-separatedNo
MailLogger.failure.notify Send build failure e-mails?