user2783484
user2783484

Reputation: 949

How to add attachment into email with out downloading into Disk?

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

Answers (1)

GregHNZ
GregHNZ

Reputation: 8969

If what you need is a DataSource and you have a URL, try using URLDataSource:

DataSource source = new URLDataSource(file);

Upvotes: 1

Related Questions