aspose file tools*
The moose likes JSP and the fly likes Send jsp page in mail as attachment Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Send jsp page in mail as attachment" Watch "Send jsp page in mail as attachment" New topic
Author

Send jsp page in mail as attachment

Varsha Goswami
Greenhorn

Joined: Jul 20, 2009
Posts: 16
I need to send a jsp page as an attachment in mail.
I am using this part in code....
But using this I am getting the entire html script in the sent mail...
Can anybody help me out...??

Properties props = System.getProperties();
String mailServer = "mail.abc.com";

props.put("mail.smtp.host", mailServer);

Logger logger = Logger.getLogger(PropertyDashboardAction.class);

// Get a mail session
Session session1 = Session.getDefaultInstance(props, null);

String from = "varsha@abc.com";
String to = "varsha@abc.com";
// Define a new mail message
Message message = new MimeMessage(session1);
message.setFrom(new InternetAddress(from));
message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
message.setSubject("Test mail");

// Create a message part to represent the body text
BodyPart messageBodyPart = new MimeBodyPart();
messageBodyPart.setText(emailStuff);

//use a MimeMultipart as we need to handle the file attachments
Multipart multipart = new MimeMultipart();

//add the message body to the mime message
multipart.addBodyPart(messageBodyPart);

// add any file attachments to the message
//addAtachments(attachments, multipart);

// Put all message parts in the message
message.setContent(multipart);

// Send the message
Transport.send(message);


Varsha
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41508
    
  53
What do you mean by "send a JSP page"? JSPs exist only in the context of a servlet container; outside of it, they are just files. Or do you mean to send an HTML page that was created by a JSP?

Also, what is "emailStuff"?


Ping & DNS - my free Android networking tools app
Varsha Goswami
Greenhorn

Joined: Jul 20, 2009
Posts: 16
I mean to say that I want to send the jsp in html form attached in a mail ... so that if a user is looking at a screen and on click of an email option he can mail that screen to any id...

code for emailstuff is here...

if(null!=printExport && printExport.equalsIgnoreCase("email")){
String emailTemplateJSP = "/jsp/propertyMgmt/propertylandingpageEmail.jsp";
RequestDispatcher rd = servlet.getServletContext().getRequestDispatcher(emailTemplateJSP);
rd.include(request, response);

// Get the generated email from the request attribute
String emailStuff = (String)request.getAttribute("test");
Jaydeep Mazumdar
Greenhorn

Joined: Aug 26, 2009
Posts: 23
I remember implementing this for one of my projects.

There is a custom tag available using which you can store the output of the JSP (i.e. HTML page) in a HttpSession attribute. I dont remember the name but you can google for the same.

You can then retrieve the contents of the HttpSession attribute and then add it as a content or as attachment.

Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41508
    
  53
I think it would be much simpler to just send the URL of the web page the user is looking at. Many people are unwilling to receive HTML content, or even have email clients that are unable to do so. And even if both are not the case, it'll be very tricky to obtain decent results (e.g., many email clients block images in HTML emails).
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Send jsp page in mail as attachment