On Mon, 8 Dec 2003, EXT-McTaggart, Peter wrote: > > > > However I would like to capture the email message (just > > thet body) and > > > save it once it has been compiled and sent. > > > > I've created a wrapper class to handle this type of situation > > for my email > > deliveries. > > > My wrapper class just extends the basic o.a.t.u.SimpleEmail and > > SimpleHtmlEmail classes, but if you would me to send you a > > copy, I would > > be happy to. Should be easy to wrap for VelocityEmail as well > > > > > > > > -- > > Regards, > > > > Jeffery Painter > > > Yes, please post a copy. I started down this path but haven't had the > time > to pursue it. > > On a slightly related point, do you or anyone else know whats up with > the commons email library -- it doesn't seem > to be listed on the jakarta home page like the other commons bits and > pieces and seems to be hidden away. > Is it destined to fade away ? is there something in the wings waiting to > take its place? > > thanks > Peter >
It has some deprecation, but does compile under the turbine-2.3 jar -------------------------------------------------------------- // com.kiasoft.util.Email /* ------------------------------------------------------------------ * Kiasoft, Inc. * PO Box 4315 * Cary, NC 27519 * http://kiasoft.com * * Copyright (c) 2003 Kiasoft, Inc. All Rights Reserved. Permission * to copy, modify and distribute this software and code * included and its documentation (collectively, the "PROGRAM") for * any purpose is hereby prohibited. * * THE PROGRAM IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT * LIMITATION, WARRANTIES THAT THE PROGRAM IS FREE OF * DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE OR * NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND * PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD ANY PART * OF THE PROGRAM PROVE DEFECTIVE IN ANY RESPECT, YOU * (NOT KIASOFT) ASSUME THE COST OF ANY NECESSARY SERVICING, * REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES * AN ESSENTIAL PART OF THIS LICENSE. NO USE OF * THE PROGRAM IS AUTHORIZED HEREUNDER EXCEPT * UNDER THIS DISCLAIMER. * * ------------------------------------------------------------------ */ package com.kiasoft.util; // JDK classes import java.util.Date; import java.util.Vector; // Turbine classes // import org.apache.turbine.util.Log; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.turbine.util.mail.SimpleEmail; import org.apache.turbine.util.mail.HtmlEmail; /** * Email.java * Email provides simple interface to email API provided * by turbine classes */ public class Email { /** Logging class from commons.logging */ private static Log log = LogFactory.getLog(Email.class); private Recipient _from = null; private String _subject = ""; private String _body = ""; private boolean _showRecipients = false; private Vector _recipient = null; // HTML Elements private String _bgColor = ""; private String _fontColor = ""; /* * Constructor */ public Email() { this._subject = "Turbine Generated Email"; this._recipient = new Vector(); this.setFrom( "[EMAIL PROTECTED]", "System Message" ); // default yellow and blue this.setBgColor("#ffff00"); this.setFontColor("#0000ff"); } /* * Setters */ public void setSubject( String x ) { this._subject = x; } public void setBgColor( String x ) { this._bgColor = x; } public void setFontColor( String x ) { this._fontColor = x; } public void setFrom( String email, String name ) { this._from = new Recipient( email, name ); } public void setBody( String x ) { this._body = x; } public void setShowRecipients( boolean x ) { this._showRecipients = x; } public void addRecipient( String email, String name ) { Recipient n = new Recipient( email, name ); this.getRecipients().add(n); return; } /* * Getters */ public String getSubject() { return this._subject; } public String getBgColor() { return this._bgColor; } public String getFontColor() { return this._fontColor; } public Recipient getFrom() { return this._from; } public String getBody() { return this._body; } public boolean getShowRecipients() { return this._showRecipients; } public Vector getRecipients() { return this._recipient; } // plain send method will force text message public void send() { this.sendTextEmail(); return; } public void sendTextEmail() { try { Vector recipients = this.getRecipients(); if ( recipients.size() > 0 ) { Date now = new Date(); Recipient from = this.getFrom(); SimpleEmail em = new SimpleEmail(); em.setFrom( from.getEmail(), from.getName() ); em.setSubject( this.getSubject() ); em.setMsg( this.getBody() ); // add each recipient for ( int i = 0; i < recipients.size(); i++ ) { Recipient to = (Recipient) recipients.elementAt(i); if ( this.getShowRecipients() ) { em.addTo( to.getEmail(), to.getName() ); } else { em.addBcc( to.getEmail(), to.getName() ); } } // send the message em.send(); } else { log.error("No recipients found!"); } } catch ( Exception e ) { log.error("Error sending text email: " + e.toString() ); } return; } public void sendHtmlEmail() { // =========================================================================== String htmlhead = "<html> " + " <head> <title> " + this.getSubject() + " </title> </head> " + " <body bgcolor=\"" + this.getBgColor() + "\" text=\"" + this.getFontColor() + "\">" + " <div align=\"left\"> " + " <font face=\"arial\" size=\"2\"> "; String htmlfoot = "</font> </div> </body> </html>"; String htmlMsg = htmlhead + this.getBody() + htmlfoot; // =========================================================================== try { Vector recipients = this.getRecipients(); if ( recipients.size() > 0 ) { Date now = new Date(); Recipient from = this.getFrom(); HtmlEmail em = new HtmlEmail(); em.setFrom( from.getEmail(), from.getName() ); em.setSubject( this.getSubject() ); em.setMsg( htmlMsg ); // add each recipient for ( int i = 0; i < recipients.size(); i++ ) { Recipient to = (Recipient) recipients.elementAt(i); if ( this.getShowRecipients() ) { em.addTo( to.getEmail(), to.getName() ); } else { em.addBcc( to.getEmail(), to.getName() ); } } // send the message em.send(); } else { log.error("No recipients found!"); } } catch ( Exception e ) { log.error("Error sending text email: " + e.toString() ); } return; } private static class Recipient { private String name = ""; private String email = ""; public Recipient() { this.email = ""; this.name = ""; } public Recipient( String email, String name ) { this.email = email; this.name = name; } public String getName() { return this.name; } public String getEmail() { return this.email; } } } -------------------------------------------------------------- -- Regards, Jeffery Painter - -- [EMAIL PROTECTED] http://kiasoft.com PGP FP: 9CE8 83A2 33FA 32B1 0AB1 4E62 E4CB E4DA 5913 EFBC -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.1 (GNU/Linux) iD8DBQE/qEQE5Mvk2lkT77wRAnMJAJ9vJ6qOkg/mvqqIpz7troCEQJ8bFACglu/U YNXabx7DZOV2Hd9LwSTmGpY= =dWiu -----END PGP SIGNATURE----- --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
