my dog learned polymorphism*
The moose likes JSP and the fly likes Sending a jsp page as the content of an email Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Sending a jsp page as the content of an email" Watch "Sending a jsp page as the content of an email" New topic

Sending a jsp page as the content of an email

Ayan Biswas
Ranch Hand

Joined: Jul 10, 2010
Posts: 104
I am using java mail api to send emails in my application.The email is getting sent properly.But I am struggling with the content where I have a jsp page that includes 2 other jsp pages(header and footer).How to send this jsp page as the content.Currently I am using the following way to set the content of the email
Certainly this is extremely tedious.Is there a way out?I am calling the content setter method (for the email) from an action class in Struts 2

Ashwini Kashyap
Ranch Hand

Joined: Aug 30, 2012
Posts: 90

I think the way in which you are proceeding is correct for sending the mail content.
I am not sure whether there is a way of sending jsp page content.
Even I had used StringBuilder instead StringBuffer to prepare HTML content and send it across via mail.

Ashwini Kashyap |
Stefan Evans

Joined: Jul 06, 2005
Posts: 1016
You might want to examine the following classes:
- javax.activation.URLDataSource class.
- javax.activation.DataHandler

Construct a DataHandler passing it the URL to include as the message part.
Hand the dataHandler off to your message - it should visit the URL you provided, and include it as the body of your email.

Consider Paul's rocket mass heater.
subject: Sending a jsp page as the content of an email
Similar Threads
jsp:setProperty and requestDispatcher.forward problem
Disable HTML frame using Javascript
How to render different pages from the SelectOneMenu
Getting ready for the job market quickly - so many technology combinations, how to focus ?
Fetch 10K rows from table