I am programming a feature in a web application that sends e-mails. I have no problem with the e-mail sending part. But now I want to attach files to the e-mails. Uploading files from a multipart form and attaching these works well. My problem is that I need to attach a
java String as a file as well. How do I do this?
The code for attaching a regular file looks like this:
File file = (File) attachments.get(i);
DataSource source = new FileDataSource(file);
BodyPart attachmentBodyPart = new MimeBodyPart();
attachmentBodyPart.setDataHandler(new DataHandler(source));
attachmentBodyPart.setFileName(file.getName());
multipart.addBodyPart(attachmentBodyPart);
It would be nice if I could something similar but with a DataSource created from a simple String.
It should be simple. Does anyone know how to do this?
(I don't want to go through the hassle of saving it as a File or anything like that)
Thanks.