send mail with attachment generated on the fly with zero footprint
843830Dec 22 2004 — edited Mar 3 2005Wish to send a mail with attachment which is created during runtime. Right now i write that to a file and then use the normal approach. But is it possible to pass the "fileoutputstream" itself to the MimeBodyPart setDataHandler or by any other way can i send mail on the fly? With zero footprint or writing anything to the storage device.Can anyone help me ?
below is an extract of my existing code....
// create and fill the first message part
MimeBodyPart mbp1 = new MimeBodyPart();
mbp1.setText(emailSubjectTxt);
// create the second message part with attachment
MimeBodyPart mbp2 = new MimeBodyPart();
// attach the file to the message
FileDataSource fds=new FileDataSource(file);
mbp2.setDataHandler(new DataHandler(fds));
mbp2.setFileName(reportName + ".xls");
// create the Multipart and add its parts to it
Multipart mp = new MimeMultipart();
mp.addBodyPart(mbp1);
mp.addBodyPart(mbp2);
// add the Multipart to the message
msg.setContent(mp);
Transport.send(msg);