File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes String value as an email attachment Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "String value as an email attachment" Watch "String value as an email attachment" New topic
Author

String value as an email attachment

seb petterson
Ranch Hand

Joined: Mar 04, 2005
Posts: 118
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.
Manuel Pettersson
Greenhorn

Joined: Dec 11, 2007
Posts: 1
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: String value as an email attachment
 
Similar Threads
Multiple Attachment Problem
How to send mail to more than one recipients
Email: java.lang.ClassFormatError
How to send java mail with big file attached
My Application is not sending mail to external servers