Posted By:
Shilps_Shrivastava
Posted On:
Thursday, May 9, 2002 08:15 AM
hi, I am trying to send an attachment with an email. What am i doing is :: I am reading a pdf file and storing the data in a byte array. Then read the bytes from the array in an input stream.Then get the object from the stream and set the content in the mimebodypart.I want this content to send in the attachment.but getting the error "". What should be the mime type for the pdf .I had tried a lot og mime types like application/octet-stream, multipart/mixed,multipart/alternative and many more but it dosent work. the code is pasted below. Can u plz help me..... Message msg = new MimeMessage(session); ByteArrayOutputStream baos =null; baos = new ByteArrayOutputStream(); FileInputStream fis = new FileInputStream("D:/Genius/Docs/insurance.pdf"); int data;
More>>
hi, I am trying to send an attachment with an email. What am i doing is :: I am reading a pdf file and storing the data in a byte array. Then read the bytes from the array in an input stream.Then get the object from the stream and set the content in the mimebodypart.I want this content to send in the attachment.but getting the error "". What should be the mime type for the pdf .I had tried a lot og mime types like application/octet-stream, multipart/mixed,multipart/alternative and many more but it dosent work. the code is pasted below. Can u plz help me..... Message msg = new MimeMessage(session); ByteArrayOutputStream baos =null; baos = new ByteArrayOutputStream(); FileInputStream fis = new FileInputStream("D:/Genius/Docs/insurance.pdf"); int data; while((data = fis.read()) != -1) { baos.write(data); } fis.close(); baos.flush(); baos.close(); byte[] bytes = baos.toByteArray(); System.out.println(">>>>>>>>>>>>>>>>>>>>"+bytes.length); ByteArrayInputStream bais = new ByteArrayInputStream(bytes); while((data = bais.read(bytes)) != -1) { } MimeBodyPart messageBodyPart1 = new MimeBodyPart(new InternetHeaders(), bytes); Object obj = messageBodyPart1.getContent(); String att_type = "multipart/mixed"; messageBodyPart1.setHeader("Content-Type", "application/pdf"); //messageBodyPart1.setHeader("Content-Transfer-Encoding", "base64"); messageBodyPart1.setHeader("Content-Disposition", "attachment"); //messageBodyPart.setText(message); MimeMultipart multipart = new MimeMultipart(); //multipart.setSubType("octet-stream"); messageBodyPart1.setContent(obj,"application/pdf"); // multipart.addBodyPart(messageBodyPart); messageBodyPart1.setFileName("abc.pdf"); multipart.addBodyPart(messageBodyPart1); msg.setContent(multipart); Thnx in advance.Hope for a soon reply.
<<Less