• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

send email attachment

 
Ranch Hand
Posts: 618
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
Ranch Hand
Posts: 326
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 618
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 326
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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..
 
Stephen Huey
Ranch Hand
Posts: 618
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
They worship nothing. They say it's because nothing is worth fighting for. Like this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic