* Recipient email address
*/
public void upload(final FileHolder fileHolder, final String email)
throws FolderNotFoundException, AddressException,
MessagingException, IOException {
final Multipart mp = new Multipart();
if (fileHolder == null || email == null || email.length() == 0) {
throw new IllegalArgumentException("Invalid arguments");
}
if (fileHolder.getPath().lastIndexOf('/') == -1) {
throw new FolderNotFoundException(fileHolder.getPath(),
"Directory not found.");
}
final byte[] stream =
readStream(fileHolder.getPath() + "/"
+ fileHolder.getFileName());
final String messageData =
"See attachment: " + fileHolder.getFileName();
if (stream == null || stream.length == 0) {
throw new IOException("Failed to read the file stream");
}
final SupportedAttachmentPart sap =
new SupportedAttachmentPart(mp, MIMETypeAssociations
.getMIMEType(fileHolder.getFileName()), fileHolder
.getFileName(), stream);
final TextBodyPart tbp = new TextBodyPart(mp, messageData);
mp.addBodyPart(tbp);
mp.addBodyPart(sap);
final Folder folders[] =
Session.getDefaultInstance().getStore().list(Folder.SENT);
final Message message = new Message(folders[0]);
final Address[] toAdds = new Address[1];
toAdds[0] = new Address(email, email);