diff --git a/announcement/plugin.jelly b/announcement/plugin.jelly index dee93dd1..58911f2e 100644 --- a/announcement/plugin.jelly +++ b/announcement/plugin.jelly @@ -40,6 +40,17 @@ + + + + + + + + + + @@ -49,6 +60,8 @@ + + @@ -97,6 +110,13 @@ + + + + + + @@ -118,6 +138,36 @@ + + + + + The SMTP server name must be specified using the maven.announcement.mail.server property + The From address must be specified using the maven.announcement.mail.from property or by ensuring that at least one developer in the POM has an email address specified + The To address must be specified using the maven.announcement.mail.to property + + + + + Sending mail using SMTP server "${maven.announcement.mail.server}", client ${maven.announcement.mail.client} and subject "${maven.announcement.mail.subject}"... + Sending from "${maven.announcement.mail.from}" to "${maven.announcement.mail.to}"... + + + + + + + + + + + + Could not send message. Reason: ${result} + + + + diff --git a/announcement/plugin.properties b/announcement/plugin.properties index 6bc2f112..e1d8aefb 100644 --- a/announcement/plugin.properties +++ b/announcement/plugin.properties @@ -33,3 +33,19 @@ # Stylesheet to use to generate the text announcement maven.announcement.stylesheet.path = ${plugin.resources}/announcement.jsl + +# IP address or name of the SMTP server used to send an announcement email +# maven.announcement.mail.server = + +# IP address or name of the host used to log on the SMTP server +maven.announcement.mail.client = localhost + +# From address to use when sending an announcement email. If not defined, +# the first email address found in the POM will be used. +# maven.announcement.mail.from = + +# Comma-separated list of addresses to use when sending an announcement email. +# maven.announcement.mail.to = + +# Mail subject to use when sending an announcement email. +maven.announcement.mail.subject = [ANN] ${pom.name} %VERSION% released diff --git a/announcement/project.xml b/announcement/project.xml index df663237..0438a82d 100644 --- a/announcement/project.xml +++ b/announcement/project.xml @@ -87,5 +87,15 @@ 20030211.142705 http://jakarta.apache.org/commons/jelly/libs/xml/ + + commons-lang + 2.0 + http://jakarta.apache.org/commons/lang/ + + + commons-net + 1.2.1 + http://jakarta.apache.org/commons/net/ + diff --git a/announcement/src/main/org/apache/maven/announcement/MailUtils.java b/announcement/src/main/org/apache/maven/announcement/MailUtils.java new file mode 100644 index 00000000..01466c3f --- /dev/null +++ b/announcement/src/main/org/apache/maven/announcement/MailUtils.java @@ -0,0 +1,137 @@ +package org.apache.maven.announcement; + +import java.io.PrintWriter; +import java.io.Writer; +import java.util.StringTokenizer; + +import org.apache.commons.net.smtp.SMTPClient; +import org.apache.commons.net.smtp.SMTPReply; +import org.apache.commons.net.smtp.SimpleSMTPHeader; + +/* ==================================================================== + * Copyright 2004 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +/** + * Send an email message using Jakarta Commons Net + * + * @author Felipe Leme + * + * @version $Id: MailUtils.java,v 1.1 2004/08/07 15:49:37 vmassol Exp $ + */ +public class MailUtils +{ + private static final String ADDRESS_SEPARATOR = ","; + + public static String sendMail(String server, String client, + String from, String to, String subject, String msg) + { + // Check arguments + if (server == null) + { + return "no smtp server configured"; + } + if (client == null) + { + return "no smtp client configured"; + } + if (to == null) + { + return "no to address specified"; + } + if (from == null) + { + return "no from address specified"; + } + if (msg == null) + { + return "no message specified"; + } + if (subject == null) + { + return "no subject specified"; + } + + // create a SMTP connection + SMTPClient smtpClient = new SMTPClient(); + System.out.println("Connecting to SMTP Server [" + server + "]"); + try + { + smtpClient.connect(server); + // checks the server reply + int reply = smtpClient.getReplyCode(); + if (!SMTPReply.isPositiveCompletion(reply)) + { + smtpClient.disconnect(); + return "SMTP server [" + server + "] refused connection."; + } + // Login + smtpClient.login(client); + // Set the sender and recipient(s) + smtpClient.setSender(from); + // parse out the to addresses + StringTokenizer st = new StringTokenizer(to.toString(), + ADDRESS_SEPARATOR); + while (st.hasMoreTokens()) + { + smtpClient.addRecipient(st.nextToken().trim()); + } + + System.out.println("Sending message from [" + from + "] to [" + + to + "]"); + + // Use the SimpleSMTPHeader class to build the header + Writer clientWriter = smtpClient.sendMessageData(); + if (clientWriter == null) + { + return "Could not send data to the SMTP server"; + } + PrintWriter writer = new PrintWriter(clientWriter); + SimpleSMTPHeader header = new SimpleSMTPHeader(from, to, subject); + + //NOTE: if would be nice to add some Maven info here + // header.addHeaderField("Organization", "xxx"); + + // Write the header to the SMTP Server + writer.write(header.toString()); + + // Write the body of the message + writer.write(msg); + + // Close the writer + writer.close(); + if (!smtpClient.completePendingCommand()) + { + return "Could not send the SMTP message"; + } + + // Logout from the e-mail server (QUIT) + smtpClient.logout(); + + // Close the connection + smtpClient.disconnect(); + + // everything is fine + return "ok"; + } + catch (Exception e) + { + e.printStackTrace(); + return e.getMessage(); + } + } + +} \ No newline at end of file diff --git a/announcement/xdocs/changes.xml b/announcement/xdocs/changes.xml index f87671fd..16d20ef8 100644 --- a/announcement/xdocs/changes.xml +++ b/announcement/xdocs/changes.xml @@ -25,6 +25,10 @@ + + Added new announcement:mail goal to automatically + send the generated announcement by email. + Added new optional maven.announcement.stylesheet.pathproperty that defines what stylesheet to use to generate the text announcement. diff --git a/announcement/xdocs/goals.xml b/announcement/xdocs/goals.xml index 5b78dbc1..eef20866 100644 --- a/announcement/xdocs/goals.xml +++ b/announcement/xdocs/goals.xml @@ -48,6 +48,12 @@ found in changes.xml + + announcement:mail + + Send the generated announcement message by email. + + diff --git a/announcement/xdocs/properties.xml b/announcement/xdocs/properties.xml index e0595a1e..9edce1cf 100644 --- a/announcement/xdocs/properties.xml +++ b/announcement/xdocs/properties.xml @@ -1,4 +1,5 @@ +