|
Thanks PC2; I wrote a class to implement DataSOurce. Now my JavaMail program runs with this InputStreamDataSource. But the attached document is always empty. I think I might not have implemented getContentType() and getOutputStream() correctly. Here is the implementation class: import javax.activation.*; import java.io.*; public class InputStreamDataSource implements DataSource { private InputStream inputStream; private OutputStream outputStream; public InputStreamDataSource(InputStream inputStream) { this.inputStream = inputStream } public InputStream getInputStream() { return inputStream } public String getContentType() { return "text/plain"; //?? } public String getName() { return "aname"; } public OutputStream getOutputStream() { //? return outputStream; } } In my java mail class I have the following: String aString = "a test string is here"; / / send this as attached doc byte[] bt = aString.getBytes(); InputStream is = new ByteArrayInputStream(bt); DataSource source = new InputStreamDataSource(is); ----- Original Message ----- From: "Clapham, Paul" <pclapham@core-mark.com> To: <java400-l@midrange.com> Sent: Friday, October 05, 2001 10:58 AM Subject: RE: JavaMail: Implement DataSource in javax.activation package > You have only four methods to implement, like this: > > getContentType(): return a string containing the MIME type of whatever's in > the input stream. You'd have to have some way of setting or determining > this. > > getInputStream(): return the input stream that you passed into the object > via its constructor. > > getName(): probably irrelevant. > > getOutputStream(): throw an IOException. > > PC2 > > -----Original Message----- > From: Bruce Jin [mailto:brucej@mrc-productivity.com] > Sent: October 5, 2001 12:38 > To: java400-l@midrange.com > Subject: JavaMail: Implement DataSource in javax.activation package > > > In my java program I need to send some generated contents as e-mail > attachment. But I found that the javax.activation only comes with a > FileDataSource that implements DataSource. This can be used to send a file: > > DataSource source = new FileDataSource(filename); > > How do I implement DataSource so that I have something like > InputStreamDataSource then I can send some generated contents in my java > program as e-mail attachment? > >
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.