Return-Path: Delivered-To: apmail-jakarta-commons-dev-archive@apache.org Received: (qmail 23273 invoked from network); 10 Oct 2002 09:28:03 -0000 Received: from unknown (HELO nagoya.betaversion.org) (192.18.49.131) by daedalus.apache.org with SMTP; 10 Oct 2002 09:28:03 -0000 Received: (qmail 21518 invoked by uid 97); 10 Oct 2002 09:28:57 -0000 Delivered-To: qmlist-jakarta-archive-commons-dev@jakarta.apache.org Received: (qmail 21465 invoked by uid 97); 10 Oct 2002 09:28:56 -0000 Mailing-List: contact commons-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Jakarta Commons Developers List" Reply-To: "Jakarta Commons Developers List" Delivered-To: mailing list commons-dev@jakarta.apache.org Received: (qmail 21443 invoked by uid 97); 10 Oct 2002 09:28:56 -0000 X-Antivirus: nagoya (v4218 created Aug 14 2002) Date: 10 Oct 2002 09:27:52 -0000 Message-ID: <20021010092752.9750.qmail@icarus.apache.org> From: jstrachan@apache.org To: jakarta-commons-sandbox-cvs@apache.org Subject: cvs commit: jakarta-commons-sandbox/jelly project.xml X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N jstrachan 2002/10/10 02:27:52 Modified: jelly/src/java/org/apache/commons/jelly jelly.properties jelly project.xml Added: jelly/src/java/org/apache/commons/jelly/tags/email EmailTag.java package.html EmailTagLibrary.java Log: Added Jason Horman's email tag library submission so that email can be sent from a Jelly script. Many thanks Jason! Also added Jason and Morgan to the development team page Revision Changes Path 1.24 +1 -0 jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/jelly.properties Index: jelly.properties =================================================================== RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/jelly.properties,v retrieving revision 1.23 retrieving revision 1.24 diff -u -r1.23 -r1.24 --- jelly.properties 28 Aug 2002 08:58:00 -0000 1.23 +++ jelly.properties 10 Oct 2002 09:27:51 -0000 1.24 @@ -17,6 +17,7 @@ html = org.apache.commons.jelly.tags.html.HTMLTagLibrary betwixt = org.apache.commons.jelly.tags.betwixt.BetwixtTagLibrary jms = org.apache.commons.jelly.tags.jms.JMSTagLibrary +email = org.apache.commons.jelly.tags.email.EmailTagLibrary validate = org.apache.commons.jelly.tags.validate.ValidateTagLibrary ojb = org.apache.commons.jelly.tags.ojb.OjbTagLibrary beanshell = org.apache.commons.jelly.tags.beanshell.BeanShellTagLibrary 1.1 jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/email/EmailTag.java Index: EmailTag.java =================================================================== /* * $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/xml/XMLTagLibrary.java,v 1.9 2002/06/18 08:31:02 jstrachan Exp $ * $Revision: 1.9 $ * $Date: 2002/06/18 08:31:02 $ * * ==================================================================== * * The Apache Software License, Version 1.1 * * Copyright (c) 1999-2002 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, if * any, must include the following acknowlegement: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowlegement may appear in the software itself, * if and wherever such third-party acknowlegements normally appear. * * 4. The names "The Jakarta Project", "Commons", and "Apache Software * Foundation" must not be used to endorse or promote products derived * from this software without prior written permission. For written * permission, please contact apache@apache.org. * * 5. Products derived from this software may not be called "Apache" * nor may "Apache" appear in their names without prior written * permission of the Apache Group. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * . * * $Id: XMLTagLibrary.java,v 1.9 2002/06/18 08:31:02 jstrachan Exp $ */ package org.apache.commons.jelly.tags.email; import org.apache.commons.jelly.TagSupport; import org.apache.commons.jelly.XMLOutput; import org.apache.commons.jelly.JellyException; import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.Log; import javax.mail.Session; import javax.mail.Message; import javax.mail.Multipart; import javax.mail.Transport; import javax.mail.internet.MimeMessage; import javax.mail.internet.InternetAddress; import javax.mail.internet.MimeBodyPart; import javax.mail.internet.MimeMultipart; import javax.activation.FileDataSource; import javax.activation.DataHandler; import java.util.Properties; import java.util.StringTokenizer; import java.util.Date; import java.io.File; import java.io.FileNotFoundException; /** * Basic tag for sending an email. Supports one attachment, multiple to addresses delimited by ";", * multiple cc addresses, etc. * * @author Jason Horman * @version $Id$ */ public class EmailTag extends TagSupport { private Log logger = LogFactory.getLog(EmailTag.class); /** smtp server */ private String server = null; /** who to send the message as */ private String from = null; /** who to send to */ private String to = null; /** who to cc */ private String cc = null; /** mail subject */ private String subject = null; /** mail message */ private String message = null; /** file attachment */ private File attachment = null; /** whether we should encode the XML body as text */ private boolean encodeXML = false; /** * Set the smtp server for the message. If not set the system * property "mail.smtp.host" will be used. */ public void setServer(String server) { this.server = server; } /** * Set the from address for the message */ public void setFrom(String from) { this.from = from; } /** * ";" seperated list of people to send to */ public void setTo(String to) { this.to = to; } /** * ";" seperated list of people to cc */ public void setCC(String cc) { this.cc = cc; } /** * Set the email subject */ public void setSubject(String subject) { this.subject = subject; } /** * Set the message body. This will override the Jelly tag body */ public void setMessage(String message) { this.message = message; } /** * Set the email attachment for the message. Only 1 attachment is supported right now */ public void setAttach(File attachment) throws FileNotFoundException { if (!attachment.exists()) { throw new FileNotFoundException("attachment not found"); } this.attachment = attachment; } /** * Sets whether we should encode the XML body as text or not. The default * is false so that the body will assumed to be valid XML */ public void setEncodeXML(boolean encodeXML) { this.encodeXML = encodeXML; } /** * Execute the tag */ public void doTag(XMLOutput xmlOutput) throws Exception { Properties props = new Properties(); props.putAll(context.getVariables()); // if a server was set then configure the system property if (server != null) { props.put("mail.smtp.host", server); } else { if (props.get("mail.smtp.host") == null) { throw new JellyException("no smtp server configured"); } } // check if there was no to address if (to == null) { throw new JellyException("no to address specified"); } // check if there was no from if (from == null) { throw new JellyException("no from address specified"); } // get the messageBody from the message attribute or from the tag body // lets insure that our body is evaluated whichever as child tags may // communicate with us to set properties etc. String messageBody = message; if (message != null) { invokeBody(xmlOutput); } else { message = getBodyText(encodeXML); } // configure the mail session Session session = Session.getDefaultInstance(props, null); // construct the mime message MimeMessage msg = new MimeMessage(session); // set the from address msg.setFrom(new InternetAddress(from)); // parse out the to addresses StringTokenizer st = new StringTokenizer(to, ";"); InternetAddress[] addresses = new InternetAddress[st.countTokens()]; int addressCount = 0; while (st.hasMoreTokens()) { addresses[addressCount++] = new InternetAddress(st.nextToken().trim()); } // set the recipients msg.setRecipients(Message.RecipientType.TO, addresses); // parse out the cc addresses if (cc != null) { st = new StringTokenizer(cc, ";"); InternetAddress[] ccAddresses = new InternetAddress[st.countTokens()]; int ccAddressCount = 0; while (st.hasMoreTokens()) { ccAddresses[ccAddressCount++] = new InternetAddress(st.nextToken().trim()); } // set the cc recipients msg.setRecipients(Message.RecipientType.CC, ccAddresses); } // set the subject if (subject != null) { msg.setSubject(subject); } // set a timestamp msg.setSentDate(new Date()); // if there was no attachment just set the text/body of the message if (attachment == null) { msg.setText(messageBody); } else { // attach the multipart mime message // setup the body MimeBodyPart mbp1 = new MimeBodyPart(); mbp1.setText(messageBody); // setup the attachment MimeBodyPart mbp2 = new MimeBodyPart(); FileDataSource fds = new FileDataSource(attachment); mbp2.setDataHandler(new DataHandler(fds)); mbp2.setFileName(fds.getName()); // create the multipart and add its parts Multipart mp = new MimeMultipart(); mp.addBodyPart(mbp1); mp.addBodyPart(mbp2); msg.setContent(mp); } logger.info("sending email to " + to + " using " + server); // send the email Transport.send(msg); } } 1.1 jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/email/package.html Index: package.html ===================================================================

Tags for sending email using the JavaMail API

1.1 jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/email/EmailTagLibrary.java Index: EmailTagLibrary.java =================================================================== /* * $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/xml/XMLTagLibrary.java,v 1.9 2002/06/18 08:31:02 jstrachan Exp $ * $Revision: 1.9 $ * $Date: 2002/06/18 08:31:02 $ * * ==================================================================== * * The Apache Software License, Version 1.1 * * Copyright (c) 1999-2002 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, if * any, must include the following acknowlegement: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowlegement may appear in the software itself, * if and wherever such third-party acknowlegements normally appear. * * 4. The names "The Jakarta Project", "Commons", and "Apache Software * Foundation" must not be used to endorse or promote products derived * from this software without prior written permission. For written * permission, please contact apache@apache.org. * * 5. Products derived from this software may not be called "Apache" * nor may "Apache" appear in their names without prior written * permission of the Apache Group. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * . * * $Id: XMLTagLibrary.java,v 1.9 2002/06/18 08:31:02 jstrachan Exp $ */ package org.apache.commons.jelly.tags.email; import org.apache.commons.jelly.TagLibrary; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; /** Describes the Taglib. This class could be generated by XDoclet * * @author James Strachan * @version $Revision: 1.9 $ */ public class EmailTagLibrary extends TagLibrary { /** The Log to which logging calls will be made. */ private Log log = LogFactory.getLog(EmailTagLibrary.class); public EmailTagLibrary() { registerTag("email", EmailTag.class); } } 1.78 +23 -0 jakarta-commons-sandbox/jelly/project.xml Index: project.xml =================================================================== RCS file: /home/cvs/jakarta-commons-sandbox/jelly/project.xml,v retrieving revision 1.77 retrieving revision 1.78 diff -u -r1.77 -r1.78 --- project.xml 4 Oct 2002 11:28:20 -0000 1.77 +++ project.xml 10 Oct 2002 09:27:52 -0000 1.78 @@ -88,6 +88,11 @@ Interested party + + Morgan Delagrange + morgand + morgand@apache.org + @@ -158,6 +163,13 @@ Developer + + Jason Horman + jhorman@musicmatch.com + + Developer + + @@ -382,6 +394,17 @@ hsqldb 1.7.0 + + + + + jaf + 1.0.2 + activation-1.0.2.jar + + + javamail + 1.2 -- To unsubscribe, e-mail: For additional commands, e-mail: