Hai to every one.
i have report in my jsp page.And i am writting thet report in PDF Format. And i want to send the PDF as E-Mail with attachment,But i dont want store the file in local machine or server,But i want to send an email with attachment..
Hai to every one.
i have report in my jsp page.And i am writting thet report in PDF Format. And i want to send the PDF as E-Mail with attachment,But i dont want store the file in local machine or server,But i want to send an email with attachment..
You have to write your own implementation of javax.activation.DataSource
to read the attachment data from an memory instead of using one of the included implementations (to read from a file, a URL, etc.). If you have the PDF report in a byte array, you can implement a DataSource which returns the byte array wrapped in a ByteArrayOutputStream.
If you use Spring's JavaMail API, you can do this sort of thing fairly easily (or at least, as easily as the JavaMail API allows, which isn't much). So you could write something like this:
JavaMailSenderImpl mailSender = ... instantiate and configure JavaMailSenderImpl here
final byte[] data = .... this holds my PDF data
mailSender.send(new MimeMessagePreparator() {
public void prepare(MimeMessage mimeMessage) throws Exception {
MimeMessageHelper helper = new MimeMessageHelper(mimeMessage);
// set from, to, subject using helper
helper.addAttachment("my.pdf", new ByteArrayResource(data));
}
});
The attachment data can be any of Spring's Resource abstractions, ByteArrayResource
is just one of them.
Note that this part of the Spring API stands on its own, it does not require (but does benefit from) the Spring container.
Hi
Since JavaMail 1.4 - mail.jar - contains javax.mail.util.ByteArrayDataSource
regards