I have the below java program which send the pdf file as an attachment and that pdf file is read from my local system and then an mail is being generated in which that pdf file is being attached and then sent
below is the code now i have a query rite now as you can see in my code that file is read from my local system and ultimately being converted and stored in a byte array but when i going to send the mail it accepts the file name as a string so i was just trying to send the same file that is the encrypted on which is stored in a byte array please advise how can i send the same file that is the byte array itself
// attachment part
MimeBodyPart attachPart = new MimeBodyPart();
String filename = "c:\\index.pdf";
String filename_src = "c:\\index.pdf";
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PdfReader reader = new PdfReader(filename_src);
PdfStamper stamper = new PdfStamper(reader, baos);
// Do the encrypting stuff
stamper.close();
byte[] result = baos.toByteArray(); //***** encrypted file in byte array ************
//*******program to send the encrypted file as an attachment ********
//accepts string as file name want to sore the above byte array itself
DataSource source = new FileDataSource(filename_dest);
attachPart.setDataHandler(new DataHandler(source));