tags:

views:

244

answers:

3

Hi gurus, I am trying to send an email with attachments and found the java mail api to be irritatingly insufficient.

There are only two implementations of javax.activation.DataHandler which mandates me to create a local file to send an attachment. May be I have to write my own implementation of DataHandler but I dont want to do that at this point.

thanks in advance !

Addy

EDIT : I meant javax.activation.DataSource not javax.activation.DataHandler

A: 

Have you tried apache commons for this task?
It has MultiPartEmail which has several overloaded attach methods.

Alberto Zaccagni
Oh thanks for that ! But even this Class wont take a String as input and send it as an attachment ! It has to be either from a file or from a URI.
anilit99
+1  A: 

Spring provides a partial wrapper around the JavaMail API, making it a bit easier to swallow.

For example, the MimeMessageHelper class allows you to add attachments using various interfaces, including from a general InputStream source.

The underlying mechanics of JavaMail are very comprehensive and robust, it's just the API that's rubbish. This addresses that concern, to a large degree.

skaffman
Yup, thats almost close to home, if you dont mind MBs worth of jars. !!
anilit99
In Spring 3, the mail stuff is in the context-support JAR which, together with its dependencies, is going to be relatively small (certainly not MBs)
skaffman
A: 

Writing a custom DataSource is pretty easy (I tossed one together for one of our apps a year ago, and it took less than an hour). If that's the only issue you are having with JavaMail, I suggest that you give it a try.

That said, I agree that JavaMail is definitely overly complex for the most common use cases.

Kevin Day