wood burning stoves 2.0*
The moose likes Java in General and the fly likes send email attachment Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "send email attachment" Watch "send email attachment" New topic
Author

send email attachment

Stephen Huey
Ranch Hand

Joined: Jul 15, 2003
Posts: 618
We have an existing Java web application that occasionally needs to send users an email with an image attachment. Right now, the J2EE web app is running on Tomcat in Windows, and we just have it exec() a process that runs the tiny little Blat program, like this:




As you can see, all I need to be able to do is send a little email with an image attachment. I don't even care if I can't BCC our log email address anymore. What would be the quickest/simplest/easiest solution to get the same functionality when we move this web app to Tomcat on Linux? From what I've read, sendmail might be a bigger deal than what I'm looking for. I'd love to be able to do it from within pure Java, but I don't know that I've run across any way to do it without getting into the whole JavaMail API...

Thanks...
Ray Stojonic
Ranch Hand

Joined: Aug 08, 2003
Posts: 326
You might take a look at Jakarta's commons-email.

It's an easy to use interface for the JavaMail package. It's also just out of the sandbox and unreleased...you'll probably have to pull it off the CVS and compile it yourself.

Anyway, I use it for html email with attachments and have had no problems.
Stephen Huey
Ranch Hand

Joined: Jul 15, 2003
Posts: 618
Thanks for the post. I'm sure I might pick up that commons package at some point. I actually don't even need HTML in my emails. Anyway, right now this guy's code is good enough for sending binary attachments:

http://www.rgagnon.com/javadetails/java-0083.html
Ray Stojonic
Ranch Hand

Joined: Aug 08, 2003
Posts: 326
Originally posted by Stephen Huey:
http://www.rgagnon.com/javadetails/java-0083.html


Ouch.

commons-email is more of a 'put stuff in envelope, address and send' approach (as opposed to the 'make paper, make ink, use ink to write letter...etc' approach)

it'll do text or html with or without attachments.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Originally posted by Stephen Huey:

I'd love to be able to do it from within pure Java, but I don't know that I've run across any way to do it without getting into the whole JavaMail API...


If you're running in Tomcat, you should look into this before going too far.
There is also an example in the /examples webapp.
http://jakarta.apache.org/tomcat/tomcat-5.5-doc/jndi-resources-howto.html

Life is much easier when you can let the container worry about setting up the mail session and deal with threads, etc..


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Stephen Huey
Ranch Hand

Joined: Jul 15, 2003
Posts: 618
Thanks. Looks good! I'm hoping we'll move from Tomcat 4 to Tomcat 5 before too long, so maybe then we can make use of that...


Happy New Year!
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

http://jakarta.apache.org/tomcat/tomcat-4.1-doc/jndi-resources-howto.html

It's in 4.1 too.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: send email attachment