I have implemented it similarly to the other lists of email addresses (To, CC, Bcc) because it might actually be easier that way We might still need a generic parameter collection for other header elements PR: 19141 Obtained from: Submitted by: Reviewed by: git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@274582 13f79535-47bb-0310-9956-ffa450edef68master
| @@ -32,6 +32,11 @@ Library Dependencies</a> for more information. | |||
| <td align="center" valign="top">Either a <code>from</code> attribute, or a <code><from></code> | |||
| element.</td> | |||
| </tr> | |||
| <tr> | |||
| <td valign="top">replyto</td> | |||
| <td valign="top">Replyto email address.</td> | |||
| <td align="center" valign="top">No</td> | |||
| </tr> | |||
| <tr> | |||
| <td valign="top">tolist</td> | |||
| <td valign="top">Comma-separated list of recipients.</td> | |||
| @@ -116,7 +121,7 @@ Library Dependencies</a> for more information. | |||
| <h3>Parameters specified as nested elements</h3> | |||
| <h4>to / cc / bcc / from</h4> | |||
| <h4>to / cc / bcc / from/ replyto </h4> | |||
| <p>Adds an email address element. It takes the following attributes:</p> | |||
| <table width="60%" border="1" cellpadding="2" cellspacing="0"> | |||
| @@ -187,7 +192,8 @@ the <code><message></code> element.</p> | |||
| <blockquote><pre> | |||
| <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 <code><message></code> element.</p> | |||
| </mail> | |||
| </pre></blockquote> | |||
| <p>Sends an eMail from <i>me@myisp.com</i> to <i>all@xyz.com</i> with a subject of | |||
| <i>Test Build</i> and attaches any zip files from the dist directory. The | |||
| <p>Sends an eMail from <i>config@myisp.com</i> to <i>all@xyz.com</i> with a subject of | |||
| <i>Test Build</i>. Replies to this email will go to <i>me@myisp.com</i>. | |||
| 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. <code>${buildname}</code> | |||
| will be replaced with the <code>buildname</code> property's value.</p> | |||
| @@ -130,6 +130,11 @@ control for turning off success or failure messages individually.</p> | |||
| <td width="63%">Mail "from" address</td> | |||
| <td width="63%">Yes, if mail needs to be sent</td> | |||
| </tr> | |||
| <tr> | |||
| <td width="337">MailLogger.replyto</td> | |||
| <td width="63%">Mail "replyto" address(es), comma-separated</td> | |||
| <td width="63%">No</td> | |||
| </tr> | |||
| <tr> | |||
| <td width="337">MailLogger.failure.notify </td> | |||
| <td width="63%">Send build failure e-mails?</td> | |||
| @@ -314,7 +319,7 @@ developers.</p> | |||
| </ul> | |||
| <hr> | |||
| <p align="center">Copyright © 2000-2002 Apache Software Foundation. All rights | |||
| <p align="center">Copyright © 2000-2003 Apache Software Foundation. All rights | |||
| Reserved.</p> | |||
| </body> | |||
| @@ -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()); | |||
| @@ -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 <a href="mailto:ishu@akm.ru">Aleksandr Ishutin</a> | |||
| * @author <a href="mailto:levylambert@tiscali-dsl.de">Antoine Levy-Lambert</a> | |||
| * @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); | |||
| @@ -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 | |||
| * | |||
| @@ -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, | |||
| @@ -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 | |||
| * | |||
| @@ -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)); | |||
| } | |||