I would suggest that slurping up the HTML from a page is the easiest way to
do this. Tapestry is one of the most sophisticated HTML generation systems
out there and it's easy to call a URL with Java so why create some other
template engine just to send email? Here is the service I use to send pages
with Amazon's email system.


public class EmailImpl implements Email {
        private final AmazonSimpleEmailService client;
        private final String source;
        private final Logger logger;
        
        public EmailImpl(AmazonSimpleEmailService client,
@Symbol(AWSConstants.EMAIL_SOURCE) String source, Logger logger) {
                this.client = client;
                this.source = source;
                this.logger = logger;
        }

        public void sendPage(String url, String subject, String plainText,
                        Collection<String> toAddresses, Collection<String> 
ccAddresses,
Collection<String> bccAddresses) {
                SendEmailRequest request = new 
SendEmailRequest().withSource(source);
                Body body = new Body().withHtml(new 
Content(getHTML(url))).withText( new
Content(plainText));
                
                Message message = new Message(new Content(subject),body);
                request.setMessage(message);
                Destination destination = new Destination();
                destination.setToAddresses(toAddresses);
                destination.setCcAddresses(ccAddresses);
                destination.setBccAddresses(bccAddresses);
                request.setDestination(destination);
                client.sendEmail(request);              
        }
        
        private String getHTML(String url) {
                try {
                        return IOUtils.toString(new URL(url).openStream());
                } catch (Exception e) {
                        logger.error("Email get HTML {} {}",url,e.getMessage());
                }
                return "";
        }       
}




--
View this message in context: 
http://tapestry.1045711.n5.nabble.com/Generating-link-url-without-RequestGlobals-tp5716546p5716565.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org

Reply via email to