Meaningless Drivel is fun!
The moose likes Struts and the fly likes sending email attachment with Struts? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "sending email attachment with Struts?" Watch "sending email attachment with Struts?" New topic

sending email attachment with Struts?

Mitch Abaza

Joined: Jul 21, 2004
Posts: 6
I'm looking for sample code that shows how to add a FormFile object as an attachment to a javax.mail.internet.MimeMessage object. All examples I have seen are using servlets and a File object, which I can't really use.

I know I can derive an InputStream from FormFile.getInputStream, and that the MimeBodyPart class takes an InputStream as a constructor, but I can't get the header information to make sense. Whenever I send the email, the attachment doesn't show up.

Here's some pseudo code that I have so far (attachment is a FormFile object):

Message message = new MimeMessage( session );
message.setFrom( new InternetAddress( address, name ) );
message.setRecipient( Message.RecipientType.BCC, ia );

Multipart multipart = new MimeMultipart();

MimeBodyPart messageBodyPart1 = new MimeBodyPart();

messageBodyPart1.setContent(bodyText, "text/plain" );


MimeBodyPart messageBodyPart2 = new MimeBodyPart(attachment.getInputStream());



Transport.send( message );

poornima balagopal
Ranch Hand

Joined: Dec 02, 2003
Posts: 83
I dont have exact idea. But in my application i was using Java Mail API for sending a mail with attachment. My requirement was to create a file at runtime and then send it as an attachment to multiple users.
I have used java mail api only. Its very simple . When we download it , we will get example . I think that will be helpful for you.

Try it ok
somkiat puisungnoen
Ranch Hand

Joined: Jul 04, 2003
Posts: 1312
In struts Framework, you can call your send mail program from Subclass of Action Class in Struts Framework.

I think, Struts Framework is a workflow control so if you understand concept of struts framework and develop application with it which help you understand in struts framework.

Java Developer, Thailand
I agree. Here's the link:
subject: sending email attachment with Struts?
It's not a secret anymore!