This week's book / license giveaways are in the JDBC and Relational Databases and Java in General forums.
We're giving away four copies each of PostGIS in Action and Java Advanced Topics Training and have the authors on-line!
See this thread and this one for details.
The moose likes Other JSE/JEE APIs and the fly likes from my screen i wanted to send mail and from screen one report will generate that i wanted to send Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "from my screen i wanted to send mail and from screen one report will generate that i wanted to send " Watch "from my screen i wanted to send mail and from screen one report will generate that i wanted to send " New topic
Author

from my screen i wanted to send mail and from screen one report will generate that i wanted to send

pallavi chaudhari
Ranch Hand

Joined: Jul 02, 2008
Posts: 54
Hi all,


In my project I have to send a mail about some confirmation report.But how can i attach that report without saving anywhere?
is there any way?

Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19968
    
  25

With a File, you usually use a DataHandler with a FileDataSource:
All you need to do then is replace the FileDataSource with another class that implemens javax.activation.DataSource; I think you'll like ByteArrayDataSource. (And of course set the file name differently.)


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
pallavi chaudhari
Ranch Hand

Joined: Jul 02, 2008
Posts: 54
Rob Prime wrote:With a File, you usually use a DataHandler with a FileDataSource:
All you need to do then is replace the FileDataSource with another class that implemens javax.activation.DataSource; I think you'll like ByteArrayDataSource. (And of course set the file name differently.)


This is my code:


Calling sendMail............



Now...need to do...

from Button present in my screen onClick of that Jasper report will be generate & I have to convert it to pdf.....and i do not know i can show this report but for sending it as attachment whether i need to store it under WEB-INF directory in some folder? how can I store it?

Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19968
    
  25

You can probably convert the report to an in-memory PDF using ByteArrayOutputStream. Then call toByteArray() on the latter and pass it to a ByteArrayDataSource as I told you.
pallavi chaudhari
Ranch Hand

Joined: Jul 02, 2008
Posts: 54
Rob Prime wrote:You can probably convert the report to an in-memory PDF using ByteArrayOutputStream. Then call toByteArray() on the latter and pass it to a ByteArrayDataSource as I told you.


Now I have used DataSource.......


calling sendMail:




To Generate Report:



To convert to PDF




But still not found solution.................???
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19968
    
  25

Correct me if I'm wrong, but doesn't buf now contain the PDF in a byte array? If so, I've told you how to create a DataSource for that byte[].
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: from my screen i wanted to send mail and from screen one report will generate that i wanted to send