• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Send jsp page in mail as attachment

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 = "[email protected]";
String to = "[email protected]";
// 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);
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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"?
 
Varsha Goswami
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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");
 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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).
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic