Reputation: 949
I have JAVA API through which i can send attachment, but i dont want to store content into disk and fetch, How can i add attachment into email with out downloading it into Disk ?
Here is how i tried it!
MimeBodyPart messageBodyPart = new MimeBodyPart();
String file = "http://example.com/2.pdf";
String fileName = "2.pdf";
DataSource source = new FileDataSource(file);
messageBodyPart.setDataHandler(new DataHandler(source));
messageBodyPart.setFileName(fileName);
mimeMultipart.addBodyPart(messageBodyPart);
Thanks!
EDIT : Here FileDataSource(file);
is expecting file from Disk not from URL!!
How Can i convert it?
Upvotes: 0
Views: 51
Reputation: 8969
If what you need is a DataSource
and you have a URL, try using URLDataSource
:
DataSource source = new URLDataSource(file);
Upvotes: 1