paul
you are right, this is a javamail issue not an iText issue, However:

It's not a terribly difficult thing to do, infact I have an application that creates reports generates the pdf and emails the reports to everyone in a list as an attachment.

what you need to do is create a datasource that implements javax.activation.DataSource that will hold your byteArray (pdf file), a filename and the mime type. (I have created a fairly generic byteArrayDataSource that can hold prety much any binary data for use as an attachment) Then you construct a multipart message in javamail. and use .setDataHandler to attach that datasource to the message.

There was a tech tip on this last year http://developer.java.sun.com/developer/JDCTechTips/2001/tt1023.html#tip2 that may help you out a bit.

-jason


On Monday, August 26, 2002, at 09:15 AM, Paul Black wrote:

I've been on the javasoft web site and searched yahoo! but no-one seems to know how to over come this.... loads of folk want to find a solution !-)

Very simply, I want to create a PDF and attach it to an email using JavaMail (mail.jar, activation.jar etc).

I can create the PDF to a file then attach that without a problem; but when trying to attach the PDF directly from a ByteArrayOutputStream (ie. in memory - from another Class that creates the PDF to an OutputStream) to a BodyPart using the setDataHandler(...) etc it fails with exceptions relating to unsupported DCH. I can convert the output to a StringBuffer the .toString(), then set the type as text/plain and the email is sent - only the PDF is corrupt (it has bytes 0a 0d in place of 0a for newlines?). There's a file in the activation.jar - mimetypes.default that has some mime types listed but not application/pdf.... I don't know why there are so few types in there.

I know this isn't really related to the iText library, but it is useful to be able to attach a PDF and send it via email.
Thanks for any help (especially code snippets!).

Paul

Reply via email to